Option Strict Off
Option Explicit On
Imports System
Imports System.IO
Imports System.Text
Imports System.Net.Sockets

Module modMain
    Public Sub Generate_EventLog(ByRef config_info As Config_Class, _
                             ByRef pltServer() As Pilot_Class, _
                             ByRef mission_info As Mission_Class, _
                             ByRef sLogInput() As String, _
                             ByVal sversion As String)
        Dim iCount As Integer
        Dim sLine As String = ""
        Dim sb As New StringBuilder()
        'FileCopy strEventFile, strProgram & "\eventlog.bak"

        ReDim Preserve sLogInput(sLogInput.Length)
        sLogInput(sLogInput.Length - 1) = "Parsed by FS_Server Ver " & sversion
        For iCount = 1 To sLogInput.Length - 1
            sb.AppendLine(sLogInput(iCount))
        Next
        Using sw As New StreamWriter(mission_info.sServer & "eventlog.dcg")
            sw.Write(sb.ToString)
        End Using
    End Sub

    Public Sub FindTime(ByVal sline As String, ByRef tmTime As Date)
        Dim iStart As Short
        Dim intEnd As Short
        Dim strTime As String
        iStart = InStr(sline, "[")
        intEnd = InStr(sline, "]")
        If iStart < 0 Or intEnd < 0 Then Exit Sub
        iStart = iStart + 1
        intEnd = (intEnd - iStart)
        strTime = Mid(sline, iStart, intEnd)
        tmTime = CDate(strTime)

    End Sub

    Public Sub logPilotBy(ByRef strLog As String, _
                          ByRef iPilot As Short, _
                          ByRef pltServer() As Pilot_Class)
        Dim iStart As Short
        Dim sPilot As String
        sPilot = ""
        iPilot = 0
        iStart = InStr(strLog, " by ") + 4
        If iStart < 1 Then Exit Sub
        sPilot = Mid(strLog, iStart)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltServer)
    End Sub
    

    Public Sub SetWinSock()
        ' The name of the Winsock control is  tcpclient.
        ' Note: to specify a remote host, you can use
        ' either the IP address (ex: "121.111.1.1") or
        ' the computer's "friendly" name, as shown here.
        'tcpclient.RemoteHost = "192.168.123.11"
        'tcpclient.RemotePort = 2000
        'tcpclient.LocalPort = 2001
    End Sub
    Public Sub ReadCFG(ByRef Config_Info As Config_Class, _
                        ByVal Mission_Info As Mission_Class)
        Dim sinput As String
        Dim iStart As Short
        If My.Computer.FileSystem.FileExists(Mission_Info.sCfg_File) Then
            Using sr As StreamReader = New StreamReader(Mission_Info.sCfg_File)
                Do Until sr.EndOfStream
                    sinput = sr.ReadLine
                    If InStr(sinput, "=") > 0 Then
                        iStart = InStr(sinput, "=")
                        If Len(sinput) > iStart Then
                            iStart = iStart + 1
                            If InStr(sinput, "WELCOMEMSG=") > 0 Then
                                Config_Info.sWelcome = Mid(sinput, iStart)
                            End If
                            If InStr(sinput, "EVENTLOG=") > 0 Then
                                Config_Info.sEventLog = Mid(sinput, iStart)
                            End If
                            If InStr(sinput, "IP=") > 0 Then
                                Config_Info.sIP = Mid(sinput, iStart)
                            End If
                            If InStr(sinput, "PORT=") > 0 Then
                                Config_Info.iPort = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "MISSIONTIME=") > 0 Then
                                Config_Info.iMissionLength = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "DELAYTIME=") > 0 Then
                                Config_Info.iDelay = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "DEATHTIME=") > 0 Then
                                Config_Info.iDeath = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "CAPTURETIME=") > 0 Then
                                Config_Info.iCapture = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "BAILTIME=") > 0 Then
                                Config_Info.iBail = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "REARMTIME=") > 0 Then
                                Config_Info.iRearm = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "FLIGHTSIZE=") > 0 Then
                                Config_Info.iFlight = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "MAXAC=") > 0 Then
                                Config_Info.iMaxAC = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "KICKSALLOWED=") > 0 Then
                                Config_Info.iKicksAllowed = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "RADARRANGE=") > 0 Then
                                Config_Info.iRadarRange = Val(Mid(sinput, iStart))
                            End If
                            If InStr(sinput, "VALIDFLIGHT=") > 0 Then
                                Config_Info.iValidFlight = Int(Val(Mid(sinput, iStart)))
                            End If
                            If InStr(sinput, "BLOCKUNREG=") > 0 Then
                                Config_Info.iBlockPlt = Int(Val(Mid(sinput, iStart)))
                            End If
                            If InStr(sinput, "TMRINTER=") > 0 Then
                                Config_Info.lInter = Int(Val(Mid(sinput, iStart)) * 10 ^ 3)
                            End If
                            If InStr(sinput, "TMGROUND=") > 0 Then
                                Config_Info.tmAllowGnd = Int(Val(Mid(sinput, iStart)))
                            End If
                            If InStr(sinput, "SUPPLYBASE=") > 0 Then
                                Config_Info.iSupBase = Int(Val(Mid(sinput, iStart)))
                            End If
                            If InStr(sinput, "WRITEPLTFILE=") > 0 Then
                                Config_Info.iWritePltFile = Int(Val(Mid(sinput, iStart)))
                            End If
                            If InStr(sinput, "DEBUG=") > 0 Then
                                Config_Info.iDebug = Int(Val(Mid(sinput, iStart)))
                            End If
                            If InStr(sinput, "BRIDGE=") > 0 Then
                                Config_Info.iBridge = Int(Val(Mid(sinput, iStart)))
                                If Config_Info.iBridge >= 1 Then
                                    Config_Info.iBridge = 1
                                Else
                                    Config_Info.iBridge = 0
                                End If
                            End If
                            If InStr(sinput, "ERRORTIMEOUT=") > 0 Then
                                Config_Info.iErrorTimeout = Int(Val(Mid(sinput, iStart)))
                            End If
                        End If

                    End If
                Loop
            End Using
        End If
    End Sub
    Public Sub WriteCFG(ByRef Config_Info As Config_Class, _
                        ByVal Mission_Info As Mission_Class)
        Dim sb As New StringBuilder
        With Config_Info
            sb.AppendLine("WELCOMEMSG=" & .sWelcome)
            sb.AppendLine("EVENTLOG=" & .sEventLog)
            sb.AppendLine("IP=" & .sIP)
            sb.AppendLine("PORT=" & Format(.iPort, "0"))
            sb.AppendLine("MISSIONTIME=" & Format(.iMissionLength, "0"))
            sb.AppendLine("DELAYTIME=" & Format(.iDelay, "0"))
            sb.AppendLine("KICKSALLOWED=" & Format(.iKicksAllowed, "0"))
            sb.AppendLine("DEATHTIME=" & Format(.iDeath, "0"))
            sb.AppendLine("CAPTURETIME=" & Format(.iCapture, "0"))
            sb.AppendLine("BAILTIME=" & Format(.iBail, "0"))
            sb.AppendLine("REARMTIME=" & Format(.iRearm, "0"))
            sb.AppendLine("FLIGHTSIZE=" & Format(.iFlight, "0"))
            sb.AppendLine("MAXAC=" & Format(.iMaxAC, "0"))
            sb.AppendLine("RADARRANGE=" & Format(.iRadarRange, "0"))
            sb.AppendLine("VALIDFLIGHT=" & Format(.iValidFlight, "0"))
            sb.AppendLine("BLOCKUNREG=" & Format(.iBlockPlt, "0"))
            sb.AppendLine("TMRINTER=" & Format(Int(.lInter / 10 ^ 3), "0"))
            sb.AppendLine("TMGROUND=" & Format(Int(.tmAllowGnd), "0"))
            sb.AppendLine("BRIDGE=" & Format(.iBridge, "0"))
            sb.AppendLine("SUPPLYBASE=" & Format(.iSupBase, "0"))
            sb.AppendLine("WRITEPLTFILE=" & Format(.iWritePltFile, "0"))
            sb.AppendLine("DEBUG=" & Format(.iDebug, "0"))
            sb.AppendLine("ERRORTIMEOUT=" & Format(.iErrorTimeout, "0"))
        End With
        Using outfile As New StreamWriter(Mission_Info.sCfg_File)
            outfile.Write(sb.ToString())
        End Using

    End Sub
    Public Sub FindFolder(ByRef sFile As String, _
                          ByRef sFolder As String)
        Dim iPos As Short
        sFolder = sFile
        If Len(sFile) < 2 Then Exit Sub
        For iPos = Len(sFile) To 1 Step -1
            If Mid(sFile, iPos, 1) = "\" Then Exit For
        Next iPos
        sFolder = Left(sFile, iPos)
    End Sub

    Public Sub LoadObjects(ByRef strFile As String, _
                           ByRef otObject() As ObjectType)
        Dim strClass(20) As String
        Dim sinput As String
        Dim intClass As Short
        Dim intMode As Short
        Dim intPos As Short
        Dim iLen As Short
        intMode = 0
        ReDim otObject(0)
        FileOpen(3, _
                 strFile, _
                 OpenMode.Input, _
                 OpenAccess.Read, _
                 OpenShare.Shared)
        Do While Not EOF(3)
            sinput = LineInput(3)
            If InStr(sinput, "[") > 0 Then
                If InStr(sinput, "fbdclass") > 0 Then intMode = 1
                If InStr(sinput, "fbdtypes") > 0 Then intMode = 2
            Else
                intPos = InStr(sinput, "=")
                iLen = Len(sinput)
                If intPos > 1 And intPos + 1 <= iLen Then
                    Select Case intMode
                        Case Is = 1
                            intClass = Val(Left(sinput, intPos - 1))
                            strClass(intClass) = Trim(Mid(sinput, intPos + 1))
                        Case Is = 2
                            ReDim Preserve otObject(otObject.Length)
                            intClass = Val(Mid(sinput, intPos + 1))
                            otObject(otObject.Length - 1).Vehicle = Trim(Left(sinput, intPos - 1))
                            otObject(otObject.Length - 1).Class_Renamed = Trim(strClass(intClass))
                    End Select
                End If
            End If
        Loop
        FileClose(3)
    End Sub
    Public Sub FindMission(ByRef config_info As Config_Class, _
                           ByRef mission_info As Mission_Class, _
                           ByRef sLogInput() As String)
        Dim sInput As String = ""
        Dim iStart As Short
        Dim iEnd As Short
        Dim sMis As String
        If My.Computer.FileSystem.FileExists(config_info.sEventLog) Then
            FileOpen(4, config_info.sEventLog, _
                     OpenMode.Input, _
                     OpenAccess.Read, _
                     OpenShare.Shared)
            Do Until EOF(4)
                sInput = LineInput(4)
                iStart = InStr(sInput, "Mission:")
                iEnd = InStr(sInput, "is Playing")
                If iStart > 0 And iEnd > 0 Then
                    sLogInput(1) = sInput
                    iStart = iStart + 8
                    sMis = Trim(Mid(sInput, iStart, iEnd - iStart))
                    mission_info.sMission = mission_info.sServer & "missions\" & sMis
                    Do
                        iStart = InStr(mission_info.sMission, "/")
                        If iStart = 0 Then Exit Do
                        mission_info.sMission = Replace(mission_info.sMission, "/", "\")
                    Loop
                End If
            Loop
            FileClose(4)

        End If
    End Sub
    Public Sub HasConn(ByRef strLog As String, _
                       ByRef pltServer() As Pilot_Class, _
                       ByRef config_info As Config_Class, _
                       ByRef mission_info As Mission_Class, _
                       ByRef pltSide() As PilotData_Class, _
                       ByRef dtPilots As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim intFound As Short
        Dim intBanPilot As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " has connected") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        'Find Pilot or add him if not there
        FindPilot(sPilot, _
                  iPilot, _
                  pltServer)
        If iPilot = 0 Then
            AddPilot(sPilot, _
                     0, _
                     pltServer, _
                     dtPilots)
            iPilot = pltServer.Length - 1
        Else
            With pltServer(iPilot)
                .sKilled = ""
                .Aircraft = "Connected"
                .Base = ""
                .Squad = 0
                .Clear = 0
                .Status = 0
                .Base = ""
                .HomeX = 0
                .HomeY = 0
                .LocX = 0
                .LocY = 0
                .Seat = 0
                .tmGround = 0
                .SupplyMission = 0
                .Allow_Drop = 0
                .InfantryMission = 0
                .iSuccess = 0
            End With

        End If
        If InStr(sPilot, " ") > 0 Then
            SendAllMess(sPilot & " space in name KICKED!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        'Check Ban list
        If intBanPilot > 1 Then
            SendAllMess(sPilot & " banned!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        'Find Pilots Side, kick if too many
        pltServer(iPilot).Side = 0
        FindPilotSide(sPilot, _
                      pltServer(iPilot).Side, _
                      pltSide, _
                      intFound)
        If pltSide(intFound).Side < 1 And config_info.iBlockPlt > 0 Then
            SendAllMess(sPilot & " Not Registered KICKED!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        Select Case pltServer(iPilot).Side
            Case 1
                mission_info.iRedSide += 1
                If mission_info.iRedSide > mission_info.iSeats Then
                    SendAllMess(sPilot & " Too many REDS is being KICKED!", _
                                config_info)
                    KickPlt(sPilot, _
                            config_info)
                    Exit Sub
                Else
                    SendPvtMess(sPilot, _
                                " RED Pilot!", _
                                config_info)
                End If
            Case 2
                mission_info.iBlueSide += 1
                If mission_info.iBlueSide > mission_info.iSeats Then
                    SendAllMess(sPilot & " Too many BLUES is being KICKED!", _
                                config_info)
                    KickPlt(sPilot, _
                            config_info)
                    Exit Sub
                Else
                    SendPvtMess(sPilot, _
                                " BLUE Pilot!", _
                                config_info)
                End If
            Case 3
                SendAllMess(sPilot & " Banned and is being KICKED!", _
                            config_info)
                KickPlt(sPilot, _
                        config_info)
                Exit Sub
            Case Else
                SendPvtMess(sPilot, _
                            " NEUTRAL Pilot!", _
                            config_info)
        End Select
        'Check for spaces in name
        If InStr(sPilot, " ") > 0 Or Len(Trim(sPilot)) < 1 Then
            SendPvtMess(sPilot, _
                        " Name error you are being KICKED!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        'Welcome pilots or tell them how much kick remains
        If pltServer(iPilot).Kick < 1 Then
            SendPvtMess(sPilot, _
                        sPilot & " " & config_info.sWelcome, _
                        config_info)
        Else
            SendPvtMess(sPilot, _
                        Str(pltServer(iPilot).Kick) & " more minutes of kick ban!", _
                        config_info)
        End If
    End Sub
    Public Sub HasDisconn(ByRef strLog As String, _
                          ByRef pltserver() As Pilot_Class, _
                          ByRef squad() As Squad_Class, _
                          ByRef infantry() As Infant_Class, _
                          ByRef mission_info As Mission_Class, _
                          ByRef sLog_Temp() As String, _
                          ByRef dtPilots As DataTable, _
                          ByRef dtSquadrons As DataTable, _
                          ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim iSquad As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " has disconnected") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot = 0 Then
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            If .Squad > 0 And .Status > 0 Then
                For iSquad = squad.Length - 1 To 1 Step -1
                    If squad(iSquad).Base = .Base And squad(iSquad).DF = .Aircraft Then
                        squad(iSquad).Number = squad(iSquad).Number + 1
                        UpDateSquadsLine(squad, _
                                 .Squad, _
                                 dtSquadrons)
                        Exit For
                    End If
                Next
                If iSquad < 1 Then
                    squad(.Squad).Number = squad(.Squad).Number + 1
                    UpDateSquadsLine(squad, _
                                    .Squad, _
                                    dtSquadrons)
                End If
            End If
            If .sKilled <> "" Then
                ReDim Preserve sLog_Temp(sLog_Temp.Length)
                sLog_Temp(sLog_Temp.Length - 1) = strLog
                strLog = .sKilled
            End If
            .sKilled = ""
            .Aircraft = "Disconnected"
            .Base = ""
            .Status = 0
            .Squad = 0
            .HomeX = 0
            .HomeY = 0
            .LocX = 0
            .LocY = 0
            .Seat = 0
            .tmGround = 0
            .SupplyMission = 0
            .Allow_Drop = 0
            .iSuccess = 0
            If .InfantryMission > 0 Then
                infantry(.InfantryMission).Status = 0
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            Select Case .Side
                Case 1
                    mission_info.iRedSide -= 1
                Case 2
                    mission_info.iBlueSide -= 1
            End Select
        End With
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Loaded_Weapons(ByRef strLog As String, _
                        ByRef pltserver() As Pilot_Class, _
                        ByRef squad() As Squad_Class, _
                        ByRef mission_info As Mission_Class, _
                        ByRef supplyac() As String, _
                        ByRef infantry() As Infant_Class, _
                        ByRef pltSide() As PilotData_Class, _
                        ByRef dtPilots As DataTable, _
                        ByRef dtSquadrons As DataTable, _
                        ByRef config_info As Config_Class)
        'Pilot has loaded weapons
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String = ""
        Dim sAC As String
        Dim iPilot As Short
        Dim iSquad As Short
        Dim sMessage As String = ""
        Dim sWeapon As String = ""
        Dim i As Short
        Dim iFuel As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " loaded weapons") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sAC = Mid(sPilot, iStart + 1)
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendAllMess(sPilot & " Kicked, cannot find you in the pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If

        With pltserver(iPilot)
            If .Kick > 0 Then
                SendAllMess(sPilot & " Kicked, you have kick time remaining!", _
                            config_info)
                KickPlt(sPilot, _
                    config_info)
                Exit Sub
            End If
            .Status = 1 'Pilot assumed to be clear to takeoff

            FindSquad(sAC, _
                      .Base, _
                      iSquad, _
                      squad)
            If iSquad < 1 Then
                SendPvtMess(sPilot, _
                            sPilot & " Cannot find " & sAC & " at " & .Base, _
                            config_info)
                SendPvtMess(sPilot, _
                            sPilot & " You are not clear to takeoff prees refly!", _
                            config_info)
                .Status = 0 'Pilot cannot takeoff
                Exit Sub
            End If

            If .Side < 1 Then
                .Side = squad(iSquad).Side
                If .Side = 1 Then mission_info.iRedSide += 1
                If .Side = 2 Then mission_info.iBlueSide += 1
                SendPvtMess(sPilot, _
                            "You have been assigned to a side!", _
                            config_info)
                UpDatePlt(pltserver(iPilot), _
                          iPilot, _
                          dtPilots)
                AddPilotSide(sPilot, _
                             .Side, _
                             pltSide)
            End If
            If .Side <> squad(iSquad).Side Then
                SendAllMess(sPilot & " Kicked, you cannot change sides! " & sPilot, _
                            config_info)
                .Status = 0
                KickPlt(sPilot, _
                        config_info)
                Exit Sub
            End If
            Select Case .Side
                Case 1
                    If mission_info.iRedSide > mission_info.iSeats Then
                        SendAllMess(sPilot & " Kicked, too many REDS! " & sPilot, _
                                    config_info)
                        .Status = 0
                        KickPlt(sPilot, _
                        config_info)
                        Exit Sub
                    End If
                Case 2
                    If mission_info.iBlueSide > mission_info.iSeats Then
                        SendAllMess(sPilot & "Kicked, too many BLUES! " & sPilot, _
                                    config_info)
                        .Status = 0
                        KickPlt(sPilot, _
                        config_info)
                        Exit Sub
                    End If

            End Select
            'Assign Base and Flight to a pilot
            .Squad = iSquad
            .Base = squad(iSquad).Base
            .Aircraft = sAC
            .tmGround = 0
            .SupplyMission = 0
            .Allow_Drop = 0
            .iSuccess = 0
            .sKilled = ""
            .InfantryMission = 0
            .sMessage = ""
            If squad(iSquad).Number < 1 Then
                .Status = 0
                sMessage = sPilot & " No more " & .Aircraft & "s available at " & .Base
                SendPvtMess(sPilot, _
                            sMessage, _
                            config_info)

            Else
                sMessage = sPilot & " " & .Aircraft & " assigned to you at " & .Base
                SendPvtMess(sPilot, _
                            sMessage, _
                            config_info)
            End If
            'Check for Supply Mission
            If squad(iSquad).Suppressed < 1 Or _
                            squad(iSquad).Base = mission_info.RedSupplyBase Or _
                            squad(iSquad).Base = mission_info.BlueSupplyBase Then
                If InStr(strLog, mission_info.sSupplyLoad) > 0 Then
                    For i = supplyac.Length - 1 To 1 Step -1
                        If InStr(strLog, supplyac(i)) > 0 Then Exit For
                    Next
                    If i > 0 Then
                        .SupplyMission = 1
                        .Allow_Drop = 1
                        sMessage = sPilot & " " & " supplies loaded on aircraft!"
                        SendPvtMess(sPilot, _
                                    sMessage, _
                                    config_info)
                    End If
                End If
            End If
            'Check for weapons
            If squad(iSquad).Suppressed > 0 Then
                If InStr(strLog, "'default'") > 0 Or InStr(strLog, "'none'") Or InStr(strLog, "Para'") Then
                    sMessage = sPilot & " Weapons OK!"
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
                Else
                    .Status = 0
                    sMessage = sPilot & " " & " Only default weapons allowed from " & .Base
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
                End If
            Else
                FindWeapon(strLog, sWeapon)

                If InStr(squad(iSquad).Weapon, ";" & sWeapon & ";") > 0 Then
                    .Status = 0
                    sMessage = sPilot & " " & sWeapon & "  not allowed in this mission!"
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)

                Else
                    sMessage = sPilot & " Weapons OK!"
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
                End If
            End If
            'Check for Infanry Mission
            If .Status > 0 Then
                If InStr(strLog, "Para'") > 0 Then
                    For i = infantry.Length - 1 To 1 Step -1
                        If infantry(i).Location = squad(iSquad).Base And infantry(i).Status < 1 Then Exit For
                    Next
                    If i > 0 Then
                        .InfantryMission = i
                        .Allow_Drop = 1
                        infantry(i).Status = 1
                        sMessage = sPilot & " " & " infantry loaded on aircraft!"
                        SendPvtMess(sPilot, _
                                    sMessage, _
                                    config_info)
                    Else
                        sMessage = sPilot & " " & " no infantry at " & .Base
                        SendPvtMess(sPilot, _
                                    sMessage, _
                                    config_info)
                        .Status = 0
                    End If
                End If
            End If
            'Check for fuel
            If squad(iSquad).FuelLimit < 100 Then
                Find_Fuel(strLog, iFuel)
                If iFuel > squad(iSquad).FuelLimit Then
                    .Status = 0
                    sMessage = sPilot & " fuel limit " & Str(squad(iSquad).FuelLimit) & "% at " & .Base
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
                Else
                    sMessage = sPilot & " fuel OK!"
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
                End If
            Else
                sMessage = sPilot & " fuel OK!"
                SendPvtMess(sPilot, _
                            sMessage, _
                            config_info)
            End If

            If .Status < 1 Then
                sMessage = sPilot & " you are not clear to takeoff press refly!"
                SendPvtMess(sPilot, _
                            sMessage, _
                            config_info)
            Else
                squad(iSquad).Number = squad(iSquad).Number - 1
                If squad(iSquad).Number < 0 Then squad(iSquad).Number = 0
                sMessage = sPilot & " your aircraft is ok!"
                SendPvtMess(sPilot, _
                            sMessage, _
                            config_info)
            End If
            If iSquad > 0 Then UpDateSquadsLine(squad, _
                                                .Squad, _
                                                dtSquadrons)
            If iPilot > 0 Then UpDatePlt(pltserver(iPilot), _
                                            iPilot, _
                                            dtPilots)
        End With
    End Sub
    Private Sub Find_Fuel(ByRef sLog As String, ByRef iFuel As Short)
        Dim iLoc As Short
        Dim sFuel As String
        iFuel = 0
        iLoc = InStr(sLog, "fuel")
        If iLoc < 1 Then Exit Sub
        sFuel = Mid(sLog, iLoc + 5)
        iLoc = InStr(sFuel, "%")
        If iLoc < 2 Then Exit Sub
        sFuel = Left(sFuel, iLoc - 1)
        iFuel = Int(Val(sFuel))
    End Sub
    Public Sub InFlight(ByRef strLog As String, _
                        ByRef pltServer() As Pilot_Class, _
                        ByRef squad() As Squad_Class, _
                        ByVal mission_info As Mission_Class, _
                        ByRef sLog_Temp() As String, _
                        ByRef dtPilots As DataTable, _
                        ByRef dtSquadrons As DataTable, _
                        ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " in flight") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltServer)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        If pltServer(iPilot).Squad < 1 Then pltServer(iPilot).Status = 0
        If mission_info.iDelayLeft > 0 Then pltServer(iPilot).Status = 0
        With pltServer(iPilot)
            If .Status < 1 Then
                SendAllMess(sPilot & " Kicked, because you are not clear to take off!", _
                            config_info)
                If pltServer(iPilot).Squad > 1 Then
                    squad(pltServer(iPilot).Squad).Number = squad(pltServer(iPilot).Squad).Number + 1
                    UpDateSquadsLine(squad, _
                                     pltServer(iPilot).Squad, _
                                     dtSquadrons)
                End If
                KickPlt(sPilot, _
                    config_info)
            Else
                .Status = 2
                SendPvtMess(sPilot, _
                            sPilot & " inflight from " & pltServer(iPilot).Base, _
                            config_info)

                If InStr(.Base, "_Chief") > 0 Then 'Take off from carrier
                    strLog = Replace(strLog, " in flight at ", " in flight from carrier " & .Base & " at ")
                Else
                    'Supply Mission Start?
                    If .SupplyMission > 0 Then
                        .SupplyMission = 2
                        SendPvtMess(sPilot, _
                                    sPilot & " supply mission started!", _
                                    config_info)
                        ReDim Preserve sLog_Temp(sLog_Temp.Length)
                        sLog_Temp(sLog_Temp.Length - 1) = Replace(strLog, " in flight at ", " supply start at ")
                    End If
                    If .InfantryMission > 0 Then
                        SendPvtMess(sPilot, _
                                    sPilot & " infantry mission started!", _
                                    config_info)
                        ReDim Preserve sLog_Temp(sLog_Temp.Length)
                        sLog_Temp(sLog_Temp.Length - 1) = Replace(strLog, " in flight at ", " infantry start at ")
                    End If
                End If
            End If
        End With
        UpDatePlt(pltServer(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Landed_at(ByRef strLog As String, _
                      ByRef pltserver() As Pilot_Class, _
                      ByRef squad() As Squad_Class, _
                      ByRef mission_info As Mission_Class, _
                      ByRef config_info As Config_Class, _
                      ByRef airbase() As Airbase_Class, _
                      ByRef infantry() As Infant_Class, _
                      ByRef sLog_Temp() As String, _
                      ByRef dtPilots As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim dblX As Double
        Dim dblY As Double
        Dim iBase As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " landed at") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot = 0 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            If config_info.iRearm > 0 Then
                If .Kick < Int(config_info.iRearm) Then
                    .Kick = Int(config_info.iRearm)
                    SendPvtMess(sPilot, _
                                sPilot & " rearming " & Str(.Kick) & " minutes before you can refly!", _
                                config_info)
                End If
            End If
        End With
        FindLoc(strLog, _
                dblX, _
                dblY)
        FindLanding(dblX, _
                    dblY, _
                    iBase, _
                    airbase)
        With pltserver(iPilot)
            If iBase < 1 Or airbase(iBase).Side <> pltserver(iPilot).Side Then
                .Aircraft = "Ditched"
                .Base = ""
                .Squad = 0
                .tmGround = 1
                If .Status > 1 Then .Status = 3
                .SupplyMission = 0
                .Allow_Drop = 0
                If .InfantryMission > 0 Then
                    infantry(.InfantryMission).Status = 0
                    .InfantryMission = 0
                    .Allow_Drop = 0
                End If
                UpDatePlt(pltserver(iPilot), _
                          iPilot, _
                          dtPilots)
                SendPvtMess(sPilot, _
                            sPilot & " you ditched your aircraft!", _
                            config_info)
                strLog = Replace(strLog, "landed at", "ditched at")
                If config_info.iBail > 0 Then
                    If .Kick < Int(config_info.iBail * 2 / 3) Then
                        .Kick = Int(config_info.iBail * 2 / 3)
                        SendPvtMess(sPilot, _
                                    Str(.Kick) & " minutes before you can refly!", _
                                    config_info)
                    End If
                End If
            Else
                .Status = 1 'landed
                .Base = airbase(iBase).Location
                SendPvtMess(sPilot, _
                            sPilot & " you landed at " & .Base, _
                            config_info)
                If .tmFlight >= config_info.iValidFlight Then .iSuccess = 2
                'Insert suffess message in eventlog

                'Check for carrier landing
                If InStr(.Base, "_Chief") > 0 Then
                    strLog = Replace(strLog, " landed at ", " landed on carrier " & .Base & " at ")
                Else
                    If .SupplyMission > 1 Then
                        SendPvtMess(sPilot, _
                                    sPilot & " supply mission completed!", _
                                    config_info)
                        .sMessage = Replace(strLog, " landed at ", " supply mission at ")
                        .iSuccess = 2
                    End If
                    If .InfantryMission > 0 Then
                        .sMessage = Replace(strLog, " landed at ", " moved " & infantry(.InfantryMission).Ident & " at ")
                        .iSuccess = 2
                    End If
                End If
                If .iSuccess > 1 Then
                    ReDim Preserve sLog_Temp(sLog_Temp.Length)
                    sLog_Temp(sLog_Temp.Length - 1) = Replace(strLog, "landed at", "successful mission at")
                End If
            End If
        End With
    End Sub
    Public Sub Refly(ByRef strLog As String, _
                     ByRef pltServer() As Pilot_Class, _
                     ByRef squad() As Squad_Class, _
                     ByRef sLog_Temp() As String, _
                     ByRef infantry() As Infant_Class, _
                     ByRef dtPilots As DataTable, _
                     ByRef dtSquadrons As DataTable, _
                     ByRef config_info As Config_Class)
        Dim sSearch As String = ""
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String = ""
        Dim iPilot As Short
        Dim iSquad As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " entered refly menu") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltServer)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        If InStr(strLog, sSearch) < 1 Then Exit Sub
        With pltServer(iPilot)
            If .Squad > 0 And .Status > 0 Then
                'Landed at different base
                For iSquad = squad.Length - 1 To 1 Step -1
                    If squad(iSquad).Base = .Base And squad(iSquad).DF = .Aircraft Then
                        squad(iSquad).Number = squad(iSquad).Number + 1
                        If .Squad = iSquad Then
                            SendPvtMess(sPilot, _
                                        .Aircraft & " returned to " & .Base, _
                                        config_info)
                        Else
                            SendPvtMess(sPilot, _
                                        sPilot & " " & .Aircraft & " ferried to " & .Base, _
                                        config_info)
                        End If
                        UpDateSquadsLine(squad, _
                                            .Squad, _
                                            dtSquadrons)
                        Exit For
                    End If
                    If .SupplyMission > 1 Then
                        If .sMessage <> "" Then
                            ReDim Preserve sLog_Temp(sLog_Temp.Length)
                            sLog_Temp(sLog_Temp.Length - 1) = strLog
                            strLog = .sMessage
                            .sMessage = ""
                        End If
                        .SupplyMission = 0
                        .Allow_Drop = 0
                        SendPvtMess(sPilot, _
                                    " supply mission completed at " & .Base, _
                                    config_info)
                    End If
                    If .InfantryMission > 0 Then
                        If .sMessage <> "" Then
                            ReDim Preserve sLog_Temp(sLog_Temp.Length)
                            sLog_Temp(sLog_Temp.Length - 1) = strLog
                            strLog = .sMessage
                            .sMessage = ""
                        End If
                        infantry(.InfantryMission).Location = .Base
                        infantry(.InfantryMission).Status = 0
                        .InfantryMission = 0
                        .Allow_Drop = 0
                        SendPvtMess(sPilot, _
                                    " infantry mission completed at " & .Base, _
                                    config_info)
                    End If
                Next
                If iSquad < 1 Then
                    squad(.Squad).Number = squad(.Squad).Number + 1
                    UpDateSquadsLine(squad, _
                                 .Squad, _
                                 dtSquadrons)
                    SendPvtMess(sPilot, _
                                .Aircraft & " returned to " & .Base, _
                                config_info)
                End If
            End If
            If .sKilled <> "" Then
                ReDim Preserve sLog_Temp(sLog_Temp.Length)
                sLog_Temp(sLog_Temp.Length - 1) = strLog
                strLog = .sKilled
            End If
            .sKilled = ""
            .Aircraft = "Refly"
            .Base = ""
            .Squad = 0
            .Status = 0
            .HomeX = 0
            .HomeY = 0
            .LocX = 0
            .LocY = 0
            .Seat = 0
            .tmGround = 0
            .iSuccess = 0
            .SupplyMission = 0
            .Allow_Drop = 0
            .InfantryMission = 0
            .sMessage = ""
        End With
        UpDatePlt(pltServer(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Bailed(ByRef strLog As String, _
                      ByRef pltserver() As Pilot_Class, _
                      ByRef squad() As Squad_Class, _
                      ByRef infantry() As Infant_Class, _
                      ByRef config_info As Config_Class, _
                      ByRef sLog_Temp() As String, _
                      ByRef dtPilots As DataTable, _
                      ByRef dtSquadrons As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim sOutput As String
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, "(0) bailed out at") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            If .Squad > 0 And .Status < 2 Then
                squad(.Squad).Number = squad(.Squad).Number + 1
                UpDateSquadsLine(squad, _
                                .Squad, _
                                dtSquadrons)
                If .InfantryMission > 0 Then
                    infantry(.InfantryMission).Status = 0
                    .InfantryMission = 0
                    .Allow_Drop = 0
                End If
            End If
            .Squad = 0
            .Aircraft = "Bailed"
            .Base = ""
            .SupplyMission = 0
            .Allow_Drop = 0
            If .Status > 1 Then .Status = 3
            If .InfantryMission > 0 Then
                iStart = InStr(strLog, "]")
                sOutput = Left(strLog, iStart) & _
                            " " & infantry(.InfantryMission).Ident & _
                            "0 destroyed by " & _
                            infantry(.InfantryMission).Ident
                iStart = InStr(strLog, "bailed out by")
                sOutput &= Mid(strLog, iStart + 13)
                For iStart = 1 To 4
                    ReDim Preserve sLog_Temp(sLog_Temp.Length)
                    sLog_Temp(iStart) = sOutput
                Next
                infantry(.InfantryMission).Status = 0
                infantry(.InfantryMission).Location = "dead"
                .InfantryMission = 0
                .Allow_Drop = 0
            End If

            If .Status > 1 Then .Status = 3
            If config_info.iBail > 0 And .Status > 1 Then
                If config_info.iBail > .Kick Then .Kick = config_info.iBail
                SendPvtMess(sPilot, _
                            "Bailed " & Str(.Kick) & " minutes before you can refly!", _
                            config_info)
            End If

        End With

        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub

    Public Sub Captured(ByRef strLog As String, _
                        ByRef pltserver() As Pilot_Class, _
                        ByRef squad() As Squad_Class, _
                        ByRef infantry() As Infant_Class, _
                        ByRef config_info As Config_Class, _
                        ByRef dtPilots As DataTable, _
                        ByRef dtSquadrons As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short

        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, "(0) was captured at ") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            If .Squad > 0 And .Status < 2 Then
                squad(.Squad).Number = squad(.Squad).Number + 1
                UpDateSquadsLine(squad, _
                                .Squad, _
                                dtSquadrons)
            End If
            .Squad = 0
            .Aircraft = "Captured"
            .Base = ""
            .SupplyMission = 0
            .Allow_Drop = 0
            .iSuccess = 0
            .Status = 0
            If .InfantryMission > 0 Then
                infantry(.InfantryMission).Status = 0
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            If config_info.iCapture > 0 And .Status > 1 Then
                If config_info.iKicksAllowed > 0 Then
                    .Kicks = .Kicks + 1
                    If .Kicks >= config_info.iKicksAllowed Then
                        .Kick = config_info.iMissionLength + config_info.iDelay
                    Else
                        If config_info.iCapture > .Kick Then .Kick = config_info.iCapture
                    End If
                    SendPvtMess(sPilot, _
                                "Captured " & Str(.Kick) & " minutes before you can refly!", _
                                config_info)
                End If
            End If
        End With
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Killed_At(ByRef strLog As String, _
                      ByRef pltserver() As Pilot_Class, _
                      ByRef squad() As Squad_Class, _
                      ByRef infantry() As Infant_Class, _
                      ByRef config_info As Config_Class, _
                      ByRef sLog_Temp() As String, _
                      ByRef dtPilots As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim sOutput As String
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, "(") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            .Squad = 0
            .Aircraft = "Dead"
            .Base = ""
            .SupplyMission = 0
            .Allow_Drop = 0
            .iSuccess = 0
            If .InfantryMission > 0 Then
                iStart = InStr(strLog, "]")
                sOutput = Left(strLog, iStart) & _
                            " " & infantry(.InfantryMission).Ident & _
                            "0 destroyed by " & _
                            infantry(.InfantryMission).Ident & "0"
                iStart = InStr(strLog, "was killed at")
                sOutput &= Mid(strLog, iStart + 13)
                For iStart = 1 To 4
                    ReDim Preserve sLog_Temp(sLog_Temp.Length)
                    sLog_Temp(iStart) = sOutput
                Next
                infantry(.InfantryMission).Status = 0
                infantry(.InfantryMission).Location = "dead"
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            If config_info.iDeath > 0 And .Status > 1 Then
                If config_info.iKicksAllowed > 0 Then
                    .Kicks = .Kicks + 1
                    If .Kicks >= config_info.iKicksAllowed Then
                        .Kick = config_info.iMissionLength + config_info.iDelay
                    Else
                        If config_info.iDeath > .Kick Then .Kick = config_info.iDeath
                    End If
                    SendPvtMess(sPilot, _
                                "Killed " & Str(.Kick) & " minutes before you can refly!", _
                                config_info)
                End If
            End If
        End With
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Killed_By(ByRef strLog As String, _
                      ByRef pltserver() As Pilot_Class, _
                      ByRef squad() As Squad_Class, _
                      ByRef infantry() As Infant_Class, _
                      ByRef config_info As Config_Class, _
                      ByRef sLog_Temp() As String, _
                      ByRef dtPilots As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String = ""
        Dim iPilot As Short
        Dim iByPilot As Short
        Dim sOutput As String
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, "(") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        'Add code to take care of spawn deaths!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        logPilotBy(strLog, _
                    iByPilot, _
                    pltserver)
        If iByPilot > 0 Then
            If pltserver(iPilot).Side = pltserver(iByPilot).Side And _
                    pltserver(iPilot).Status <> 2 And _
                    pltserver(iByPilot).Status <> 2 Then
                squad(pltserver(iPilot).Squad).Number += 1
                strLog = ""
                If pltserver(iPilot).InfantryMission > 0 Then
                    infantry(pltserver(iPilot).InfantryMission).Status = 0
                    pltserver(iPilot).InfantryMission = 0
                    pltserver(iPilot).Allow_Drop = 0
                End If
            End If
        End If
        With pltserver(iPilot)
            .sKilled = Replace(strLog, "(0) was killed by ", " shot down by ")
            .Squad = 0
            .Aircraft = "Dead"
            .Base = ""
            .SupplyMission = 0
            .Allow_Drop = 0
            If .Status > 1 Then .Status = 3
            If .InfantryMission > 0 Then
                iStart = InStr(strLog, "]")
                sOutput = Left(strLog, iStart) & _
                            " " & infantry(.InfantryMission).Ident & _
                            "0 destroyed by"
                iStart = InStr(strLog, "was killed by")
                sOutput &= Mid(strLog, iStart + 13)
                For iStart = 1 To 4
                    ReDim Preserve sLog_Temp(sLog_Temp.Length)
                    sLog_Temp(iStart) = sOutput
                Next
                infantry(.InfantryMission).Status = 0
                infantry(.InfantryMission).Location = "dead"
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            If config_info.iDeath > 0 And .Status > 1 Then
                If config_info.iKicksAllowed > 0 Then
                    .Kicks = .Kicks + 1
                    If .Kicks >= config_info.iKicksAllowed Then
                        .Kick = config_info.iMissionLength + config_info.iDelay
                    Else
                        If config_info.iDeath > .Kick Then .Kick = config_info.iDeath
                    End If
                    SendPvtMess(sPilot, _
                                "Killed " & Str(.Kick) & " minutes before you can refly!", _
                                config_info)
                End If
            End If
        End With

        If iByPilot > 0 And _
                pltserver(iPilot).Side <> pltserver(iByPilot).Side _
                Then pltserver(iByPilot).iSuccess = 1
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtpilots)
    End Sub
    Public Sub Killed_In_Chute(ByRef strLog As String, _
                     ByRef pltserver() As Pilot_Class, _
                     ByRef squad() As Squad_Class, _
                     ByRef infantry() As Infant_Class, _
                     ByRef config_info As Config_Class, _
                     ByRef dtPilots As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim iByPilot As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, "(") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        If pltserver(iPilot).Status > 1 Then pltserver(iPilot).Status = 3
        If InStr(strLog, " in his chute by ") > 0 Then
            logPilotBy(strLog, _
                       iByPilot, _
                       pltserver)
            If iByPilot > 0 Then
                If pltserver(iPilot).Side <> pltserver(iByPilot).Side Then Exit Sub
            End If
        End If
        With pltserver(iPilot)
            'Add code to take care of spawn deaths!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            .sKilled = Replace(strLog, "(0) was killed in his chute by ", " shot down by ")
            .Squad = 0
            .Aircraft = "Dead"
            .Base = ""
            .SupplyMission = 0
            .Allow_Drop = 0
            If .InfantryMission > 0 Then
                infantry(.InfantryMission).Status = 0
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            If config_info.iDeath > 0 And .Status > 1 Then
                If config_info.iKicksAllowed > 0 Then
                    .Kicks = .Kicks + 1
                    If .Kicks >= config_info.iKicksAllowed Then
                        .Kick = config_info.iMissionLength + config_info.iDelay
                    Else
                        If config_info.iDeath > .Kick Then .Kick = config_info.iDeath
                    End If
                    SendPvtMess(sPilot, _
                                "Killed " & Str(.Kick) & " minutes before you can refly!", _
                                config_info)
                End If
            End If
        End With
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Damaged_By(ByRef strLog As String, _
                      ByRef pltserver() As Pilot_Class)

        Dim iByPilot As Short
        Dim iPilot As Integer
        Dim istart As Integer
        Dim iLen As Integer
        Dim spilot As String
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " damaged by") - istart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If istart > 0 Then
            spilot = Left(spilot, istart - 1)
            FindPilot(spilot, _
                      iPilot, _
                      pltserver)
            If iPilot > 0 Then
                If pltserver(iPilot).sKilled = "" Then
                    pltserver(iPilot).sKilled = Replace(strLog, " damaged by ", " shot down by ")
                End If
            End If
        End If
        logPilotBy(strLog, _
                    iByPilot, _
                    pltserver)
        If iByPilot > 0 Then pltserver(iByPilot).iSuccess = 1

    End Sub
    Public Sub ShotDown(ByRef strLog As String, _
                        ByRef pltserver() As Pilot_Class, _
                        ByRef squad() As Squad_Class, _
                        ByRef infantry() As Infant_Class, _
                        ByRef config_info As Config_Class, _
                        ByRef mission_info As Mission_Class, _
                        ByRef sLog_Temp() As String, _
                        ByRef dtPilots As DataTable, _
                        ByRef dtSquadrons As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String = ""
        Dim iPilot As Short
        Dim sX As String = ""
        Dim sY As String = ""
        Dim strMess As String
        Dim ibyPilot As Integer
        Dim sOutput As String
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " shot down by") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If

        logPilotBy(strLog, _
                    ibyPilot, _
                    pltserver)
        If ibyPilot > 0 Then
            'Add code to take care of spawn deaths!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            If pltserver(iPilot).Side = pltserver(ibyPilot).Side And _
                    pltserver(iPilot).Status <> 2 And _
                    pltserver(ibyPilot).Status <> 2 Then
                squad(pltserver(iPilot).Squad).Number += 1
                strLog = ""
                If pltserver(iPilot).InfantryMission > 0 Then
                    infantry(pltserver(iPilot).InfantryMission).Status = 0
                    pltserver(iPilot).InfantryMission = 0
                    pltserver(iPilot).Allow_Drop = 0
                End If
            End If
        End If
        With pltserver(iPilot)
            .sKilled = ""
            .Squad = 0
            .Aircraft = "Shot Down"
            .Base = ""
            .Status = 3
            .SupplyMission = 0
            .Allow_Drop = 0
            If .InfantryMission > 0 Then
                iStart = InStr(strLog, "]")
                sOutput = Left(strLog, iStart) & _
                            " " & infantry(.InfantryMission).Ident & _
                            "0 destroyed by"
                iStart = InStr(strLog, "shot down by")
                sOutput &= Mid(strLog, iStart + 12)
                For iStart = 1 To 4
                    ReDim Preserve sLog_Temp(sLog_Temp.Length)
                    sLog_Temp(iStart) = sOutput
                Next
                infantry(.InfantryMission).Status = 0
                infantry(.InfantryMission).Location = "dead"
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            UpDatePlt(pltserver(iPilot), _
                      iPilot, _
                      dtPilots)
            UpDateSquadsLine(squad, _
                                .Squad, _
                                dtSquadrons)
            If .Side > 0 And strLog <> "" Then
                FindCoord(strLog, _
                          sX, _
                          sY, _
                          mission_info)
                strMess = "Aircraft lost at:" & sX & sY
                SendArmyMess(strMess, _
                             .Side, _
                             config_info)
            End If
        End With
    End Sub
    Public Sub Crashed(ByRef strLog As String, _
                       ByRef pltserver() As Pilot_Class, _
                       ByRef squad() As Squad_Class, _
                       ByRef infantry() As Infant_Class, _
                       ByRef config_info As Config_Class, _
                       ByRef mission_info As Mission_Class, _
                       ByRef dtPilots As DataTable, _
                       ByRef dtSquadrons As DataTable)
        Dim sAC As String
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String = ""
        Dim iPilot As Short
        Dim sX As String = ""
        Dim sY As String = ""
        Dim sMess As String

        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " crashed at") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        'UPGRADE_WARNING: Couldn't resolve default property of object sAC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        sAC = Mid(sPilot, iStart + 1)
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If

        With pltserver(iPilot)
            If .Squad > 0 And .Status < 2 Then
                squad(.Squad).Number = squad(.Squad).Number + 1
                UpDateSquadsLine(squad, _
                                .Squad, _
                                dtSquadrons)
            End If
            .sKilled = ""
            .Squad = 0
            .Aircraft = "Crashed"
            .Base = ""
            If .Status > 0 Then .Status = 3
            If .Side > 0 Then
                FindCoord(strLog, _
                          sX, _
                          sY, _
                          mission_info)
                sMess = "Aircraft crashed at:" & sX & sY
                SendArmyMess(sMess, _
                             .Side, _
                             config_info)
            End If
        End With
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)

    End Sub
    Public Sub Damaged_On_Ground(ByRef strLog As String, _
                       ByRef pltserver() As Pilot_Class, _
                       ByRef squad() As Squad_Class, _
                       ByRef infantry() As Infant_Class, _
                       ByRef config_info As Config_Class, _
                       ByRef mission_info As Mission_Class, _
                       ByRef dtPilots As DataTable)
        Dim sAC As String = ""
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String = ""
        Dim iPilot As Short
        Dim sX As String = ""
        Dim sY As String = ""
        Dim sMess As String

        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " damaged on the ground at ") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sAC = Mid(sPilot, iStart + 1)
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            .Squad = 0
            .Aircraft = "Crashed"
            .Base = ""
            .iSuccess = 0
            If .Status > 1 Then .Status = 3
            If .Side > 0 Then
                FindCoord(strLog, _
                          sX, _
                          sY, _
                          mission_info)
                sMess = "Aircraft damaged on ground at:" & sX & sY
                SendArmyMess(sMess, _
                             .Side, _
                             config_info)
            End If
        End With
        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Destroyed_By(ByRef strLog As String, _
                            ByRef logdestroy() As DestObj, _
                            ByRef squad() As Squad_Class, _
                            ByRef mission_info As Mission_Class, _
                            ByRef missline() As String, _
                            ByRef airbase() As Airbase_Class, _
                            ByRef pltServer() As Pilot_Class, _
                            ByRef config_info As Config_Class, _
                            ByRef dtSquadrons As DataTable, _
                            ByRef transport() As Carry, _
                            ByRef sLog_Temp() As String)
        Dim i As Short
        Dim iStart As Short
        Dim iLen As Short
        Dim strObject1 As String = ""
        Dim strObject2 As String = ""
        Dim strSearch As String = ""
        Dim dbX As Double
        Dim dbY As Double
        Dim sX As String = ""
        Dim sY As String = ""
        Dim iside As Short
        Dim strMess As String
        Dim sBase As String = ""
        Dim sType As String = ""
        Dim iSup As Short
        Dim iFuel As Short
        Dim sPilot As String = ""
        Dim iPilot As Integer
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, " destroyed by ") - iStart
        strObject1 = Mid(strLog, iStart, iLen)
        strSearch = " " & strObject1
        iStart = InStr(strLog, " destroyed by ") + 14
        iLen = InStr(strLog, " at ") - iStart
        strObject2 = Trim(Mid(strLog, iStart, iLen))

        FindCoord(strLog, _
                  sX, _
                  sY, _
                  mission_info)
        If InStr(strObject1, "ridge") > 0 Then
            strMess = "INTEL: Bridge destroyed at: " & sX & sY
            ReDim Preserve logdestroy(logdestroy.Length)
            logdestroy(logdestroy.Length - 1).Text = strMess
            logdestroy(logdestroy.Length - 1).Side = 1
            ReDim Preserve logdestroy(logdestroy.Length)
            logdestroy(logdestroy.Length - 1).Text = strMess
            logdestroy(logdestroy.Length - 1).Side = 2
            iStart = InStr(strObject2, ":")
            If iStart > 1 And config_info.iBridge > 0 Then
                sPilot = Left(strObject2, iStart - 1)
                FindPilot(sPilot, _
                            iPilot, _
                            pltServer)
                If iPilot > 0 Then
                    If pltServer(iPilot).Side Then
                        pltServer(iPilot).iSuccess = 1
                    End If
                End If
            End If
        Else
            If transport.Length > 1 Then
                For i = 1 To transport.Length - 1
                    If strSearch.Contains(" " & transport(i).Main) Then
                        ReDim Preserve sLog_Temp(sLog_Temp.Length)
                        sLog_Temp(sLog_Temp.Length - 1) = strLog.Replace(transport(i).Main, transport(i).Secondary)
                    End If
                Next
            End If
            SearchMiss(strObject1, _
                       sType, _
                       iside, _
                       missline)
            If InStr(strObject2, ":") > 0 Then
                If InStr(sType, "Plane$") > 1 Then
                    strMess = strObject1 & " destroyed on the ground by air attack at: " & sX & sY
                Else
                    strMess = "Ground units destroyed by air attack at: " & sX & sY
                End If
                iStart = InStr(strObject2, ":")
                If iStart > 1 Then
                    sPilot = Left(strObject2, iStart - 1)
                    FindPilot(sPilot, _
                                iPilot, _
                                pltServer)
                    If iPilot > 0 Then
                        If pltServer(iPilot).Side <> iside Then
                            pltServer(iPilot).iSuccess = 1
                        End If
                    End If
                End If
            Else
                If InStr(sType, "Plane$") > 1 Then
                    strMess = strObject1 & " destroyed on the ground by ground attack at: " & sX & sY
                Else
                    strMess = "Ground units destroyed by ground fire at: " & sX & sY
                End If
            End If
            If logdestroy.Length < 2 Then
                ReDim Preserve logdestroy(logdestroy.Length)
                logdestroy(logdestroy.Length - 1).Text = strMess
                logdestroy(logdestroy.Length - 1).Side = iside
            Else
                For i = logdestroy.Length - 1 To 1 Step -1
                    If InStr(logdestroy(i).Text, "Ground units") > 0 And _
                                    logdestroy(logdestroy.Length - 1).Side = iside And _
                                    InStr(logdestroy(i).Text, sX & sY) > 0 Then
                        Exit For
                    End If
                Next
                If i > 1 Then
                    ReDim Preserve logdestroy(logdestroy.Length)
                    logdestroy(logdestroy.Length - 1).Text = strMess
                    logdestroy(logdestroy.Length - 1).Side = iside
                End If
            End If
            'Remove an aircraft from the airbase attacked
            If InStr(sType, "Plane$") > 1 Then
                FindBase(strLog, _
                         sBase, _
                         dbX, _
                         dbY, _
                         iSup, _
                         iFuel, _
                         airbase)
                For i = 1 To squad.Length - 1
                    With squad(i)
                        If .Base = sBase And .Coop = strObject1 Then
                            If .Number > 0 Then .Number = .Number - 1
                            UpDateSquadsLine(squad, _
                                             i, _
                                             dtSquadrons)
                            Exit For
                        End If
                    End With
                Next
            End If
        End If

    End Sub
    Public Sub UpDatePlt(ByVal pltserver As Pilot_Class, _
                         ByVal iPilot As Integer, _
                         ByRef dtPilots As DataTable)
        Dim rows() As DataRow
        Dim sSearch As String
        sSearch = "Callsign='" & pltserver.CallSign & "'"
        rows = dtPilots.Select(sSearch)
        If rows.Length > 0 Then
            rows(0)("Callsign") = pltserver.CallSign
            rows(0)("Squad") = pltserver.Squad
            rows(0)("Aircraft") = pltserver.Aircraft
            rows(0)("Base") = pltserver.Base
            rows(0)("Side") = pltserver.Side
            rows(0)("Kick") = pltserver.Kick
            rows(0)("Kicks") = pltserver.Kicks
            rows(0)("LocX") = pltserver.LocX
            rows(0)("LocY") = pltserver.LocY
            rows(0)("HomeX") = pltserver.HomeX
            rows(0)("HomeY") = pltserver.HomeY
        Else
            Dim newrow As DataRow = dtPilots.NewRow
            newrow("Callsign") = pltserver.CallSign
            newrow("Squad") = pltserver.Squad
            newrow("Aircraft") = pltserver.Aircraft
            newrow("Base") = pltserver.Base
            newrow("Side") = pltserver.Side
            newrow("Kick") = pltserver.Kick
            newrow("Kicks") = pltserver.Kicks
            newrow("LocX") = pltserver.LocX
            newrow("LocY") = pltserver.LocY
            newrow("HomeX") = pltserver.HomeX
            newrow("HomeY") = pltserver.HomeY
            dtPilots.Rows.Add(newrow)
        End If

    End Sub
    Public Sub AddPilot(ByVal sPilot As String, _
                        ByVal iside As Short, _
                        ByRef pltserver() As Pilot_Class, _
                        ByRef dtPilots As DataTable)
        ReDim Preserve pltserver(pltserver.Length)
        With pltserver(pltserver.Length - 1)
            .CallSign = sPilot
            .Aircraft = ""
            .Side = iside
            .Kick = 0
            .Kicks = 0
            .LocX = 0
            .LocY = 0
            .HomeX = 0
            .HomeY = 0
            .Squad = 0
        End With
        UpDatePlt(pltserver(pltserver.Length - 1), _
                  pltserver.Length - 1, _
                  dtPilots)
    End Sub
    Public Sub FindPilot(ByRef sPilot As String, _
                         ByRef iPilot As Integer, _
                         ByRef pltServer() As Pilot_Class)
        For iPilot = pltServer.Length - 1 To 1 Step -1
            If sPilot = pltServer(iPilot).CallSign Then Exit For
        Next
    End Sub

    Public Sub KickPlt(ByRef sPilot As String, _
                       ByVal config_info As Config_Class)

        TCPSend(config_info, "kick " & sPilot & vbCrLf)
    End Sub

    Public Sub SendPvtMess(ByRef strTo As String, _
                           ByVal sMessage As String, _
                           ByRef config_info As Config_Class)
        sMessage = "chat " & sMessage & " TO " & strTo & vbCrLf
        TCPSend(config_info, _
            sMessage)
    End Sub
    Public Sub FindCoord(ByRef strLog As String, _
                         ByRef sX As String, _
                         ByRef sY As String, _
                         ByRef mission_info As Mission_Class)
        Dim intX As Short
        Dim intY As Short
        Dim iStart As Short
        Dim iLen As Short
        iStart = InStr(strLog, " at ") + 4
        iLen = InStr(iStart, strLog, " ") - iStart
        sX = Mid(strLog, iStart, iLen)
        intX = Int((Val(sX) - mission_info.XOffset) / 10000) + 1
        iStart = InStr(iStart + 1, strLog, " ")
        sY = Mid(strLog, iStart)
        intY = Int((Val(sY) - mission_info.YOffset) / 10000)
        sY = Str(intY + 1)
        sX = ""
        sX = Chr(65 + intX \ 26)
        sX = sX & Chr(64 + intX Mod 26)

    End Sub
    Public Sub FindLoc(ByRef strLog As String, ByRef dblX As Double, ByRef dblY As Double)
        Dim iStart As Short
        Dim iLen As Short
        iStart = InStr(strLog, " at ") + 4
        iLen = InStr(iStart, strLog, " ") - iStart
        dblX = Val(Mid(strLog, iStart, iLen))
        iStart = InStr(iStart + 1, strLog, " ")
        dblY = Val(Mid(strLog, iStart))

    End Sub
    Public Sub SendAllMess(ByVal sMessage As String, _
                           ByRef config_info As Config_Class)

        sMessage = "chat " & sMessage & " ALL" & vbCrLf
        TCPSend(config_info, _
                sMessage)
    End Sub
    Public Sub SendArmyMess(ByRef sMessage As String, _
                            ByRef intArmy As Short, _
                            ByRef config_info As Config_Class)
        sMessage = "chat " & sMessage & " ARMY" & Str(intArmy) & vbCrLf
        TCPSend(config_info, _
                sMessage)
    End Sub
    Public Sub EndMission(ByRef config_info As Config_Class, _
                          ByRef mission_info As Mission_Class, _
                          ByRef spltside() As PilotData_Class)
        If config_info.iWritePltFile > 0 Then GenPilotSide(mission_info, _
                                                            spltside)
        TCPSend(config_info, _
                "mission END" & vbCrLf)
    End Sub
    Public Sub StopServer(ByRef config_info As Config_Class, _
                          ByRef pltserver() As Pilot_Class, _
                          ByRef mission_info As Mission_Class, _
                          ByRef sloginput() As String, _
                          ByRef Transport() As Carry, _
                          ByRef airbase() As Airbase_Class, _
                          ByRef FLM() As Marker_Class, _
                          ByVal sversion As String)

        frmMain.tmrInter.Enabled = False
        Generate_EventLog(config_info, _
                        pltserver, _
                        mission_info, _
                        sloginput, _
                        sversion)
        TCPSend(config_info, _
                "exit" & vbCrLf)
        With frmMain
            .cmdConnect.Enabled = True
            .cmdExit.Enabled = True
            .GroupBox1.Enabled = True
            .GroupBox2.Enabled = True
            .GroupBox3.Enabled = True
            .GroupBox4.Enabled = True
            .gbRadar.Enabled = True
            .gbBridge.Enabled = False
            .gbBases.Enabled = False
            .cmdConnect.Enabled = True
            .cmdExit.Enabled = True
            .cmdsave.Enabled = True
        End With

    End Sub

    Public Sub SearchMiss(ByRef strObject1 As String, _
                          ByRef sType As String, _
                          ByRef iside As Short, _
                          ByVal missline() As String)
        Dim iStart As Integer
        Dim sinput As String
        Dim intCount As Short
        For intCount = 1 To missline.Length - 1
            sinput = missline(intCount)
            If InStr(" " & sinput, " " & strObject1) > 0 Then
                sType = sinput
                iStart = InStr(sType, ".")
                sType = Mid(sType, iStart)
                iStart = InStr(sType, "$")
                sType = Left(sType, iStart)
                strObject1 = sinput
                iStart = InStr(strObject1, "$") + 1
                strObject1 = Mid(strObject1, iStart)
                iStart = InStr(strObject1, " ") - 1
                strObject1 = Left(strObject1, iStart)
                iStart = InStr(sinput, "$") + 1
                sinput = Mid(sinput, iStart)
                iStart = InStr(sinput, " ") + 1
                sinput = Mid(sinput, iStart)
                iStart = InStr(sinput, " ")
                sinput = Left(sinput, iStart)
                iside = Val(sinput)
                Exit For
            End If
        Next

    End Sub

    Public Sub Status(ByRef strLog As String, _
                      ByRef pltserver() As Pilot_Class, _
                      ByRef mission_info As Mission_Class, _
                      ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim sAC As String
        Dim iPilot As Short
        Dim sMessage As String
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        sAC = pltserver(iPilot).Aircraft
        sMessage = Str(mission_info.iTimeLeft) & " minutes to mission end!"
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
        sMessage = Str(pltserver(iPilot).Kick) & " minutes of kick remaining!"
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
        sMessage = Str(pltserver(iPilot).Kicks) & " deaths/captures in this mission!"
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
        sMessage = "Time in flight: " & Format(pltserver(iPilot).tmFlight, "0") & " minutes this mission."
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)


    End Sub

    Public Sub Aircraft(ByRef strLog As String, _
                        ByVal pltServer() As Pilot_Class, _
                        ByVal squad() As Squad_Class, _
                        ByRef config_info As Config_Class)
        Dim iSide As Integer
        Dim iStart As Integer
        Dim iLen As Integer
        Dim sPilot As String = ""
        Dim iPilot As Integer
        Dim iSquad As Integer
        Dim sMessage As String
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltServer)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        If squad.Length < 2 Then Exit Sub
        With pltServer(iPilot)
            iSide = .Side
            If .Squad > 0 Then iSide = 3
            Select Case iSide
                Case 0
                    SendPvtMess(sPilot, _
                                "Select an airfield, press fly and then use this command!", _
                                config_info)
                Case 1, 2
                    For iSquad = 1 To squad.Length - 1
                        If .Side = squad(iSquad).Side And squad(iSquad).Number > 0 Then
                            sMessage = squad(iSquad).Coop & " AT " & squad(iSquad).Base & " Available:" & Str(squad(iSquad).Number)
                            SendPvtMess(sPilot, _
                                        sMessage, _
                                        config_info)
                        End If
                    Next

                Case 3
                    sMessage = "AT " & .Base
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
                    For iSquad = 1 To squad.Length - 1
                        If .Base = squad(iSquad).Base And _
                                    .Side = squad(iSquad).Side And _
                                    squad(iSquad).Number > 0 Then
                            sMessage = squad(iSquad).Coop & " Available:" & Str(squad(iSquad).Number)
                            SendPvtMess(sPilot, _
                                        sMessage, _
                                        config_info)
                        End If
                    Next
                    If .Status > 0 Then
                        sMessage = "You are assigned a " & .Aircraft
                    Else
                        sMessage = "You are NOT clear to takeoff in this Aircraft"
                    End If
                    SendPvtMess(sPilot, _
                                sMessage, _
                                config_info)
            End Select
        End With
    End Sub


    Public Sub TimeLeft(ByRef strLog As String, _
                        ByVal iTimeLeft As Integer, _
                        ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim sMessage As String
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        sMessage = Str(iTimeLeft) & " minutes to mission end!"
        SendAllMess(sMessage, _
                    config_info)
    End Sub

    Public Sub Settings(ByRef strLog As String, _
                        ByVal config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim sMessage As String
        With config_info
            iStart = InStr(strLog, "Chat: ") + 6
            iLen = InStr(strLog, ": \t") - iStart
            sPilot = Mid(strLog, iStart, iLen)
            sMessage = "Mission length " & Str(.iMissionLength) & " minutes!"
            SendPvtMess(sPilot, _
                        sMessage, _
                        config_info)
            sMessage = "Kicks allowed " & Str(.iKicksAllowed) & " !"
            SendPvtMess(sPilot, _
                        sMessage, _
                        config_info)
            sMessage = "Death kick " & Str(.iDeath) & " minutes!"
            SendPvtMess(sPilot, _
                        sMessage, _
                        config_info)
            sMessage = "Capture kick " & Str(.iCapture) & " minutes!"
            SendPvtMess(sPilot, _
                        sMessage, _
                        config_info)
            sMessage = "Bail kick " & Str(.iBail) & " minutes!"
            SendPvtMess(sPilot, _
                        sMessage, _
                        config_info)
            If .iRadarRange > 0 Then
                sMessage = "Radar: Active Range: " & Str(.iRadarRange) & "km"
            Else
                sMessage = "Radar: Inactive"
            End If
        End With
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
    End Sub

    Public Sub Version(ByRef strLog As String, _
                       ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim sMessage As String
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        sMessage = "Version " & Str(My.Application.Info.Version.Major) & "." & Str(My.Application.Info.Version.Minor) & "." & Str(My.Application.Info.Version.Revision)
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
    End Sub
    Public Sub FrontLine(ByRef strFile As String, _
                         ByRef flRed() As Marker_Class, _
                         ByRef flBlue() As Marker_Class)
        Dim sinput As String
        Dim intPos As Short
        Dim iLen As Short
        Dim iside As Short
        Dim dbX As Double
        Dim dbY As Double
        ReDim flRed(0)
        ReDim flBlue(0)
        FileOpen(10, strFile, OpenMode.Input)
        Do Until EOF(10)
            sinput = LineInput(10)
            intPos = InStr(sinput, "  FrontMarker")
            If intPos > 0 Then
                intPos = InStr(intPos + 2, sinput, " ") + 1
                iLen = InStr(intPos, sinput, " ") - intPos
                dbX = Val(Mid(sinput, intPos, iLen))
                intPos = InStr(intPos, sinput, " ") + 1
                iLen = InStr(intPos, sinput, " ") - intPos
                dbY = Val(Mid(sinput, intPos, iLen))
                intPos = InStr(intPos + 1, sinput, " ")
                iside = Val(Mid(sinput, intPos))
                If iside = 1 Then
                    ReDim Preserve flRed(flRed.Length)
                    flRed(flRed.Length - 1).X = dbX
                    flRed(flRed.Length - 1).Y = dbY
                Else
                    ReDim Preserve flBlue(flBlue.Length)
                    flBlue(flBlue.Length - 1).X = dbX
                    flBlue(flBlue.Length - 1).Y = dbY
                End If
            End If
        Loop
        FileClose(10)
    End Sub


    Public Sub Toggle_Smoke(ByVal strLog As String, _
                      ByRef pltserver() As Pilot_Class, _
                      ByRef config_info As Config_Class, _
                      ByRef mission_info As Mission_Class, _
                      ByRef flRed() As Marker_Class, _
                      ByRef flBlue() As Marker_Class, _
                      ByRef sLog_Temp() As String, _
                      ByRef infantry() As Infant_Class, _
                       ByRef dtPilots As DataTable)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim dblX As Double
        Dim dblY As Double
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(iStart, strLog, ":") - iStart
        If iStart < 1 Then Exit Sub
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            FindLoc(strLog, dblX, dblY)
            .LocX = dblX
            .LocY = dblY
            If config_info.iRadarRange > 0 Then
                Select Case .Side
                    Case Is = 1
                        Radar(2, _
                              dblX, _
                              dblY, _
                               flRed, _
                               flBlue, _
                               config_info.iRadarRange, _
                               mission_info, _
                               config_info)
                    Case Is = 2
                        Radar(1, _
                              dblX, _
                              dblY, _
                               flRed, _
                               flBlue, _
                               config_info.iRadarRange, _
                               mission_info, _
                               config_info)
                End Select
            End If
            If .SupplyMission > 1 And .Allow_Drop > 0 Then
                SendPvtMess(sPilot, _
                            " supply drop made!", _
                            config_info)
                ReDim Preserve sLog_Temp(sLog_Temp.Length)
                sLog_Temp(sLog_Temp.Length - 1) = Replace(strLog, " turned wingtip smokes on at ", " supply drop at ")
                .SupplyMission = 0
                .Allow_Drop = 0
            End If
            If .InfantryMission > 0 And .Allow_Drop > 0 Then
                SendPvtMess(sPilot, _
                            " infantry drop made!", _
                            config_info)
                ReDim Preserve sLog_Temp(sLog_Temp.Length)
                sLog_Temp(sLog_Temp.Length - 1) = Replace(strLog, " turned wingtip smokes on at ", " moved " & infantry(.InfantryMission).Ident & " at ")
                infantry(.InfantryMission).Status = 0
                infantry(.InfantryMission).Location = "dropped"
                .InfantryMission = 0
                .Allow_Drop = 0
            End If
            UpDatePlt(pltserver(iPilot), _
                      iPilot, _
                      dtPilots)
        End With
    End Sub
    Public Sub Radar(ByRef iside As Short, _
                     ByRef dblX As Double, _
                     ByRef dblY As Double, _
                     ByRef flRed() As Marker_Class, _
                     ByRef flBlue() As Marker_Class, _
                     ByRef iRange As Integer, _
                     ByRef mission_info As Mission_Class, _
                     ByRef config_info As Config_Class)
        Dim intLine As Short
        Dim intX As Integer
        Dim intY As Integer
        Dim intDistance As Integer
        Dim sX As String
        Dim sY As String
        Dim sMessage As String
        If flRed.Length < 2 Then Exit Sub
        If flBlue.Length < 2 Then Exit Sub
        Select Case iside
            Case Is = 1
                For intLine = 1 To flRed.Length - 1
                    intX = Int((dblX - flRed(intLine).X) / 1000)
                    intY = Int((dblY - flRed(intLine).Y) / 1000)
                    intDistance = Int(System.Math.Sqrt(intX ^ 2 + intY ^ 2))
                    If iRange >= intDistance Then
                        intX = Int((dblX - mission_info.XOffset) / 10000)
                        intY = Int((dblY - mission_info.YOffset) / 10000)
                        sY = Str(intY + 1)
                        sX = ""
                        sX = Chr(65 + intX \ 26)
                        sX = sX & Chr(65 + (intX Mod 26))
                        sMessage = "Enemy aircraft spotted: " & sX & sY
                        SendArmyMess(sMessage, _
                                     iside, _
                                     config_info)
                        sMessage = "Friendly aircraft spotted: " & sX & sY
                        SendArmyMess(sMessage, _
                                     2, _
                                    config_info)
                        Exit For
                    End If
                Next
                For intLine = flBlue.Length - 1 To 1 Step -1
                    intX = Int((dblX - flBlue(intLine).X) / 1000)
                    intY = Int((dblY - flBlue(intLine).Y) / 1000)
                    intDistance = Int(System.Math.Sqrt(intX ^ 2 + intY ^ 2))
                    If iRange >= intDistance Then
                        intX = Int((dblX - mission_info.XOffset) / 10000)
                        intY = Int((dblY - mission_info.YOffset) / 10000)
                        sY = Str(intY + 1)
                        sX = ""
                        sX = Chr(65 + intX \ 26)
                        sX = sX & Chr(65 + (intX Mod 26))
                        sMessage = "Friendly aircraft spotted: " & sX & sY
                        SendArmyMess(sMessage, _
                                     2, _
                                    config_info)
                        Exit For
                    End If
                Next
            Case Is = 2
                For intLine = flBlue.Length - 1 To 1 Step -1
                    intX = Int((dblX - flBlue(intLine).X) / 1000)
                    intY = Int((dblY - flBlue(intLine).Y) / 1000)
                    intDistance = Int(System.Math.Sqrt(intX ^ 2 + intY ^ 2))
                    If iRange >= intDistance Then
                        intX = Int((dblX - mission_info.XOffset) / 10000)
                        intY = Int((dblY - mission_info.YOffset) / 10000)
                        sY = Str(intY + 1)
                        sX = ""
                        sX = Chr(65 + intX \ 26)
                        sX = sX & Chr(65 + (intX Mod 26))
                        sMessage = "Enemy aircraft spotted: " & sX & sY
                        SendArmyMess(sMessage, _
                                     iside, _
                                    config_info)
                        sMessage = "Friendly aircraft spotted: " & sX & sY
                        SendArmyMess(sMessage, _
                                     1, _
                                    config_info)
                        Exit For
                    End If
                Next
                For intLine = 1 To flRed.Length - 1
                    intX = Int((dblX - flRed(intLine).X) / 1000)
                    intY = Int((dblY - flRed(intLine).Y) / 1000)
                    intDistance = Int(System.Math.Sqrt(intX ^ 2 + intY ^ 2))
                    If iRange >= intDistance Then
                        intX = Int((dblX - mission_info.XOffset) / 10000)
                        intY = Int((dblY - mission_info.YOffset) / 10000)
                        sY = Str(intY + 1)
                        sX = ""
                        sX = Chr(65 + intX \ 26)
                        sX = sX & Chr(65 + (intX Mod 26))
                        sMessage = "Friendly aircraft spotted: " & sX & sY
                        SendArmyMess(sMessage, _
                                     1, _
                                     config_info)
                        Exit For
                    End If
                Next
            Case Else


        End Select

    End Sub
    Public Sub Home(ByRef strLog As String, _
                    ByVal pltServer() As Pilot_Class, _
                    ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim sMessage As String
        Dim intX As Short
        Dim intY As Short
        Dim intHead As Double
        Dim intDistance As Short
        Dim dbRatio As Double
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltServer)
        If iPilot = 0 Then Exit Sub
        intX = Int((pltServer(iPilot).HomeX - pltServer(iPilot).LocX) / 1000)
        intY = Int((pltServer(iPilot).HomeY - pltServer(iPilot).LocY) / 1000)
        intDistance = Int(System.Math.Sqrt(intX ^ 2 + intY ^ 2))
        If intY = 0 Then
            intHead = 90
        Else
            dbRatio = System.Math.Abs(intX) / System.Math.Abs(intY)
            intHead = Int(System.Math.Atan(dbRatio) * 180 / 3.14)
        End If
        If intX > -1 Then
            If intY < 0 Then
                intHead = 180 - intHead
            End If
        Else
            If intY < 0 Then
                intHead = 180 + intHead
            Else
                intHead = 360 - intHead
            End If
        End If
        sMessage = "Heading to Homebase: " & Str(intHead) & " Distance: " & Str(intDistance) & "km"
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
    End Sub
    Private Function invCos(ByRef rlRatio As Double) As Double
        invCos = (System.Math.Atan(-rlRatio / System.Math.Sqrt(-rlRatio * rlRatio + 1)) + 2 * System.Math.Atan(1)) * 180 / 3.14
    End Function
    Public Sub FindOffset(ByRef mission_info As Mission_Class)
        Dim sLine As String
        With mission_info
            .XOffset = 0
            .YOffset = 0
            If My.Computer.FileSystem.FileExists(.sMission) Then
                Using sr As New StreamReader(.sMission)
                    Do Until sr.EndOfStream
                        sLine = sr.ReadLine
                        If InStr(sLine, "MAP") > 0 Then
                            If InStr(sLine, "Marianas/") > 0 Or InStr(sLine, "marianas/") > 0 Then
                                .XOffset = -300000
                                .YOffset = -300000
                            End If
                            If InStr(sLine, "Guadal/") > 0 Or InStr(sLine, "guadal/") > 0 Then
                                .XOffset = -340000
                                .YOffset = -380000
                            End If
                            If InStr(sLine, "Midway/") > 0 Or InStr(sLine, "midway/") > 0 Then
                                .XOffset = -180000
                                .YOffset = 0
                            End If
                            If InStr(sLine, "Tarawa/") > 0 Or InStr(sLine, "tarawa/") > 0 Then
                                .XOffset = -500000
                                .YOffset = -500000
                            End If
                            If InStr(sLine, "Cat_Midway/") > 0 Or InStr(sLine, "cat_midway/") > 0 Then
                                .XOffset = -179200
                                .YOffset = -183000
                            End If
                            Exit Do
                        End If
                    Loop
                End Using
            End If
        End With
    End Sub
    Public Sub FindServerSize(ByRef sServer As String, _
                              ByRef iServerSize As Short)
        Dim sinput As String = ""
        Dim iStart As Short
        Dim iEnd As Short
        Dim sConf As String
        iServerSize = 0
        sConf = sServer & "\confs.ini"
        If My.Computer.FileSystem.FileExists(sConf) Then
            FileOpen(5, _
                     sConf, _
                     OpenMode.Input, _
                     OpenAccess.Read, _
                     OpenShare.Shared)
            Do Until EOF(5)
                sinput = LineInput(5)
                iStart = InStr(sinput, "serverChannels")
                iEnd = InStr(sinput, "=")
                If iStart > 0 And iEnd > 0 Then
                    iServerSize = Val(Mid(sinput, iEnd + 1))
                End If
            Loop
            FileClose(5)
        End If
    End Sub
    Public Sub LoadPilotSide(ByRef sFile As String, _
                             ByRef pltSide() As PilotData_Class)
        Dim iStart As Short
        Dim sInput As String = ""
        Dim sPilot As String
        Dim sSide As String
        Dim sIP As String
        Dim i As Integer
        If My.Computer.FileSystem.FileExists(sFile) Then
            FileOpen(9, sFile, _
                     OpenMode.Input, _
                     OpenAccess.Read, _
                     OpenShare.Shared)
            Do Until EOF(9)
                sInput = LineInput(9)
                sPilot = ""
                sSide = ""
                sIP = ""
                i = 0
                Do Until sInput = ""
                    iStart = InStr(sInput, ",")
                    Select Case i
                        Case 0
                            If iStart > 1 Then
                                sPilot = Trim(Left(sInput, iStart - 1))
                            End If
                        Case 1
                            If iStart > 1 Then
                                sSide = Trim(Left(sInput, iStart - 1))
                            Else
                                sSide = Trim(sInput)
                                sInput = ""
                            End If
                        Case Else
                            sIP = Trim(sInput)
                            sInput = ""
                    End Select
                    If Len(sInput) > iStart Then
                        sInput = Trim(Mid(sInput, iStart + 1))
                    Else
                        sInput = ""
                    End If
                    i += 1
                Loop

                ReDim Preserve pltSide(pltSide.Length)
                With pltSide(pltSide.Length - 1)
                    .CallSign = sPilot
                    .Side = Val(sSide)
                    .IP = Trim(sIP)
                End With
            Loop
            EOF(9)
        End If
    End Sub
    Public Sub GenPilotSide(ByRef mission_info As Mission_Class, _
                            ByVal sPltSide() As PilotData_Class)
        Dim iPilot As Short
        Dim sb As StringBuilder
        If sPltSide.Length > 1 Then
            sb = New StringBuilder
            For iPilot = 1 To sPltSide.Length - 1
                With sPltSide(iPilot)
                    sb.AppendLine(.CallSign & "," & Format(.Side, "0") & "," & .IP)
                End With
            Next
            Using sw As New StreamWriter(mission_info.sPilotSideFile)
                sw.Write(sb.ToString)
            End Using
        End If
    End Sub

    Public Sub FindPilotSide(ByRef sPilot As String, _
                             ByRef iSide As Short, _
                             ByRef pltside() As PilotData_Class, _
                             ByRef iFound As Short)

        iSide = 0
        For iFound = pltside.Length - 1 To 1 Step -1
            If LCase(sPilot) = LCase(pltside(iFound).CallSign) Then
                iSide = pltside(iFound).Side
                Exit For
            End If
        Next

    End Sub
    Public Sub AddPilotSide(ByRef sPilot As String, _
                            ByRef iSide As Short, _
                            ByRef pltside() As PilotData_Class)
        Dim iPilot As Short
        For iPilot = pltside.Length - 1 To 1 Step -1
            With pltside(iPilot)
                If LCase(sPilot) = LCase(.CallSign) Then
                    .Side = iSide
                    Exit For
                End If
            End With
        Next
        If iPilot < 1 Then
            ReDim Preserve pltside(pltside.Length)
            With pltside(pltside.Length - 1)
                .CallSign = Trim(sPilot)
                .Side = iSide
                .IP = "0.0.0.0"
            End With
        End If
    End Sub

    Public Sub FindMinute(ByRef sMessage As String, ByRef intMinute As Short)

        Dim intEnd As Short
        intMinute = 0
        If InStr(sMessage, "PM]") > 0 Then intMinute = 720
        intEnd = InStr(sMessage, ":")
        If intEnd < 1 Then Exit Sub
        intMinute = intMinute + (60 * Val(Mid(sMessage, 2, intEnd - 2)))
        intMinute = intMinute + Val(Mid(sMessage, intEnd + 1, 2))
    End Sub


    Public Sub logPilotAC(ByRef strLog As String, _
                          ByRef iPilot As Short, _
                          ByRef pltserver() As Pilot_Class)
        Dim iStart As Short
        Dim sPilot As String
        sPilot = ""
        iPilot = 0
        iStart = InStr(strLog, "] ") + 2
        sPilot = Mid(strLog, iStart)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
    End Sub

    Public Sub logPilot(ByRef strLog As String, _
                        ByRef iPilot As Short, _
                        ByRef pltserver() As Pilot_Class)
        Dim iStart As Short
        Dim sPilot As String
        sPilot = ""
        iPilot = 0
        iStart = InStr(strLog, "] ") + 2
        If iStart < 1 Then Exit Sub
        sPilot = Mid(strLog, iStart)
        iStart = InStr(sPilot, " ")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
    End Sub

    Public Sub Seat_Occupied_By(ByRef strLog As String, _
                    ByRef pltserver() As Pilot_Class, _
                    ByRef airbase() As Airbase_Class, _
                    ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim iSup As Short
        Dim iFuel As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(iStart, strLog, ":") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Error, cannot find you in the pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            iStart = InStr(strLog, "(") + 1
            iLen = InStr(iStart, strLog, ")") - iStart
            .Seat = Int(Val(Mid(strLog, iStart, iLen)))
            If .Status < 1 Then
                FindBase(strLog, _
                         .Base, _
                         .HomeX, _
                         .HomeY, _
                         iSup, _
                         iFuel, _
                         airbase)
                If InStr(.Base, "_Chief") > 0 Then
                    strLog = Replace(strLog, " seat occupied ", " " & .Base & " seat occupied on carrier " & .Base & " ")
                End If
            End If
        End With

    End Sub

    Public Sub Help(ByRef strLog As String, _
                    ByRef Config_Info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim sMessage As String
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        sMessage = " status - your pilots status"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
        sMessage = " aircraft - aircraft availability"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
        sMessage = " timeleft - time until mission ends"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
        sMessage = " settings - server settings"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
        sMessage = " ver - server version"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
        sMessage = " home - toggle smoke first"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
        sMessage = " sides - pilot count"
        SendPvtMess(sPilot, _
                    sMessage, _
                    Config_Info)
    End Sub
    Public Sub LoadMission(ByRef mission_info As Mission_Class, _
                           ByRef missline() As String, _
                           ByRef FLM() As Marker_Class)
        Dim sline As String = ""
        Dim ipos As Short
        Dim dX As Double
        Dim dY As Double
        Dim iSide As Short
        FileOpen(8, _
                mission_info.sMission, _
                OpenMode.Input, _
                OpenAccess.Read, _
                OpenShare.Shared)
        Do Until EOF(8)
            sline = LineInput(8)
            ReDim Preserve missline(missline.Length)
            missline(missline.Length - 1) = sline
            If InStr(missline(missline.Length - 1), "FrontMarker") > 0 Then
                sline = Trim(missline(missline.Length - 1))
                ipos = InStr(sline, " ")
                If ipos > 0 Then
                    sline = Mid(sline, ipos)
                    ipos = ipos = InStr(sline, " ")
                    If ipos > 0 Then
                        dX = Val(Left(sline, ipos))
                        sline = Mid(sline, ipos)
                        ipos = ipos = InStr(sline, " ")
                        If ipos > 0 Then
                            dY = Val(Left(sline, ipos))
                            sline = Mid(sline, ipos)
                            If Len(sline) > 1 Then
                                iSide = Val(sline)
                                ReDim Preserve FLM(FLM.Length)
                                With FLM(FLM.Length - 1)
                                    .X = dX
                                    .Y = dY
                                    .Side = iSide
                                End With

                            End If
                        End If
                    End If
                End If
            End If
        Loop
        FileClose(8)
    End Sub

    Public Sub LoadBases(ByRef AirBase() As Airbase_Class, _
                         ByRef Squad() As Squad_Class, _
                         ByRef mission_info As Mission_Class, _
                         ByRef config_info As Config_Class, _
                         ByRef dtSquadrons As DataTable, _
                         ByRef dtAirBases As DataTable)
        Dim sInput As String = ""
        Dim i As Integer
        FileOpen(7, _
                mission_info.sPropFile, _
                OpenMode.Input, _
                OpenAccess.Read, _
                OpenShare.Shared)
        Do Until EOF(7)
            sInput = LineInput(7)
            If sInput.Contains("<ARMY BASES>") And _
                    sInput.Contains("</ARMY BASES>\n") Then
                sInput = Replace(sInput, "<ARMY BASES>", "")
                sInput = Replace(sInput, "</ARMY BASES>\n", "")
                Dim strArray() As String
                strArray = sInput.Split(":")
                ReDim Preserve AirBase(AirBase.Length)
                For i = 0 To strArray.Length - 1
                    If i > 8 Then
                        Dim sAC() As String
                        sAC = strArray(i).Split("=")
                        If sAC.Length = 3 Then
                            ReDim Preserve Squad(Squad.Length)
                            With Squad(Squad.Length - 1)
                                .Coop = sAC(0)
                                .DF = sAC(1)
                                .Number = Int(Val(sAC(2)))
                                .Base = AirBase(AirBase.Length - 1).Location
                                .Side = AirBase(AirBase.Length - 1).Side
                                .Suppressed = AirBase(AirBase.Length - 1).Suppressed
                                .FuelLimit = AirBase(AirBase.Length - 1).FuelLimit
                                .X = AirBase(AirBase.Length - 1).X
                                .Y = AirBase(AirBase.Length - 1).Y
                            End With
                            UpDateSquadsLine(Squad, _
                                             Squad.Length - 1, _
                                             dtSquadrons)
                        End If
                    Else
                        With AirBase(AirBase.Length - 1)
                            If i = 0 Then .Location = strArray(i)
                            If i = 1 Then .Side = Int(Val(strArray(i)))
                            If i = 2 Then .X = Val(strArray(i))
                            If i = 3 Then .Y = Val(strArray(i))
                            If i = 4 Then .Radius = Val(strArray(i))
                            If i = 5 Then .Supplies = Val(strArray(i))
                            If i = 6 Then .Fuel = Val(strArray(i))
                            If i = 7 Then .Suppressed = Val(strArray(i))
                            If i = 8 Then .FuelLimit = Val(strArray(i))
                        End With
                        UpDateBases(AirBase, _
                                    AirBase.Length - 1, _
                                    dtAirBases)
                    End If
                Next
            End If
        Loop
        FileClose(7)

    End Sub

    Public Sub FindLanding(ByRef dblX As Double, _
                           ByRef dblY As Double, _
                           ByRef iBase As Short, _
                           ByRef airbase() As Airbase_Class)
        Dim dblDistance As Double
        Dim i As Integer
        Dim dbBase As Double
        iBase = 0
        dbBase = 100000
        For i = 1 To airbase.Length - 1
            With airbase(i)
                dblDistance = System.Math.Sqrt(((dblX - .X) ^ 2) + ((dblY - .Y) ^ 2))
                If dblDistance <= .Radius Then
                    If dblDistance < dbBase Then
                        dbBase = dblDistance
                        iBase = i
                    End If
                End If
            End With
        Next
    End Sub

    Public Sub FindBase(ByRef strLog As String, _
                        ByRef strBase As String, _
                        ByRef dbX As Double, _
                        ByRef dbY As Double, _
                        ByRef iSuppressed As Short, _
                        ByRef iFuelLimit As Short, _
                        ByRef airbase() As Airbase_Class)

        Dim dbXBase As Double
        Dim dbYBase As Double
        Dim dbDist As Double
        Dim iStart As Short
        Dim iEnd As Short
        Dim iBase As Integer
        dbDist = 100000
        iStart = InStr(strLog, " at ") + 4
        iEnd = InStr(iStart, strLog, " ")
        dbX = Val(Mid(strLog, iStart, iEnd - iStart))
        iStart = iEnd + 1
        dbY = Val(Mid(strLog, iStart))
        For iBase = airbase.Length - 1 To 1 Step -1
            With airbase(iBase)
                dbXBase = airbase(iBase).X
                dbYBase = airbase(iBase).Y
                If dbDist > System.Math.Sqrt(((dbX - dbXBase) ^ 2) + ((dbY - dbYBase) ^ 2)) Then
                    dbDist = System.Math.Sqrt(((dbX - dbXBase) ^ 2) + ((dbY - dbYBase) ^ 2))
                    strBase = .Location
                    iSuppressed = .Suppressed
                    iFuelLimit = .FuelLimit
                End If
            End With
        Next
        'SendAllMess("Distance = " & Format(dbDist, "0.0"))
    End Sub
    Public Sub FindSquad(ByRef sAircraft As String, _
                         ByRef sBase As String, _
                         ByRef iSquad As Short, _
                         ByRef squad() As Squad_Class)
        'Find the squad that has aircrft at that base
        For iSquad = squad.Length - 1 To 1 Step -1
            With squad(iSquad)
                If .Base = sBase And .DF = sAircraft Then
                    Exit For
                End If
            End With
        Next
    End Sub


    Public Sub UpDateSquadsLine(ByRef Squad() As Squad_Class, _
                                ByRef iSquad As Short, _
                                ByRef dtSquadrons As DataTable)
        Dim rows() As DataRow
        Dim sSearch As String
        sSearch = "Coop='" & Squad(iSquad).Coop & "' And Base='" & Squad(iSquad).Base & "'"
        rows = dtSquadrons.Select(sSearch)
        If rows.Length > 0 Then
            rows(0)("Coop") = Squad(iSquad).Coop
            rows(0)("DF") = Squad(iSquad).DF
            rows(0)("Base") = Squad(iSquad).Base
            rows(0)("Side") = Squad(iSquad).Side
            rows(0)("Available") = Squad(iSquad).Number
            rows(0)("Weapons") = Squad(iSquad).Weapon
            rows(0)("Suppressed") = Squad(iSquad).Suppressed
            rows(0)("Fuel_Limit") = Squad(iSquad).FuelLimit
            rows(0)("X") = Squad(iSquad).X
            rows(0)("Y") = Squad(iSquad).Y
        Else
            Dim newrow As DataRow = dtSquadrons.NewRow
            newrow("Coop") = Squad(iSquad).Coop
            newrow("DF") = Squad(iSquad).DF
            newrow("Base") = Squad(iSquad).Base
            newrow("Side") = Squad(iSquad).Side
            newrow("Available") = Squad(iSquad).Number
            newrow("Weapons") = Squad(iSquad).Weapon
            newrow("Suppressed") = Squad(iSquad).Suppressed
            newrow("Fuel_Limit") = Squad(iSquad).FuelLimit
            newrow("X") = Squad(iSquad).X
            newrow("Y") = Squad(iSquad).Y
            dtSquadrons.Rows.Add(newrow)
        End If

    End Sub

    Public Sub FindWeapon(ByRef sline As String, ByRef sWeapon As String)
        Dim iStart As Short
        Dim intEnd As Short
        iStart = InStr(sline, " '")
        iStart = iStart + 2
        intEnd = InStr(sline, "' ")
        sWeapon = Mid(sline, iStart, intEnd - iStart)
    End Sub
    Public Sub TimerInter(ByRef sline As String, _
                          ByRef mission_info As Mission_Class, _
                          ByRef config_info As Config_Class, _
                          ByRef pltserver() As Pilot_Class, _
                          ByRef sloginput() As String, _
                          ByRef Transport() As Carry, _
                          ByRef airbase() As Airbase_Class, _
                          ByRef pltSide() As PilotData_Class, _
                          ByRef LogDestroy() As DestObj, _
                          ByRef Squad() As Squad_Class, _
                          ByRef Infantry() As Infant_Class, _
                          ByRef SupplyAC() As String, _
                          ByRef MissLine() As String, _
                          ByRef flRed() As Marker_Class, _
                          ByRef flBlue() As Marker_Class, _
                          ByRef carrier() As CarrierType, _
                          ByRef carrierwp() As CarrierWPType, _
                          ByRef FLM() As Marker_Class, _
                          ByRef dtPilots As DataTable, _
                          ByRef dtSquadrons As DataTable, _
                          ByVal sversion As String)
        Dim iStart As Short
        Dim dbTime As Double
        Dim iTimeElapsed As Short
        Dim iPilot As Short
        Dim lLine As Integer
        Dim sPrevious As String = ""
        Dim sinput As String = ""
        Dim iCount As Short
        Dim sLog_Temp() As String
        Dim lFileSize As Long
        Dim iPilot2 As Integer
        Dim wasKilledIndex As String
        Dim sdate As Date = CDate("00:00")
        mission_info.iWaiting = 0
        If mission_info.bMissEnd Then
            StopServer(config_info, _
                         pltserver, _
                         mission_info, _
                         sloginput, _
                         Transport, _
                         airbase, _
                         FLM, _
                         sversion)

            Exit Sub
        End If
        If System.Drawing.ColorTranslator.ToOle(frmMain.lbPoll.BackColor) = QBColor(12) Then
            frmMain.lbPoll.BackColor = System.Drawing.ColorTranslator.FromOle(QBColor(10))
        Else
            frmMain.lbPoll.BackColor = System.Drawing.ColorTranslator.FromOle(QBColor(12))
        End If
        iStart = InStr(sline, "Time Of Day:")
        If iStart < 1 Then Exit Sub
        dbTime = Val(Mid(sline, iStart + 12))
        If mission_info.dbMissStartTime < 1 Then mission_info.dbMissStartTime = dbTime
        iTimeElapsed = Int(60 * (dbTime - mission_info.dbMissStartTime))
        If (config_info.iMissionLength + config_info.iDelay - iTimeElapsed) < mission_info.iTimeLeft Then

            mission_info.iTimeLeft = (config_info.iMissionLength + config_info.iDelay - iTimeElapsed)
            frmMain.tbTimeLeft.Text = Str(mission_info.iTimeLeft)
            For iPilot = pltserver.Length - 1 To 1 Step -1
                If pltserver(iPilot).Kick > 0 Then
                    pltserver(iPilot).Kick = pltserver(iPilot).Kick - 1
                    UpDatePlt(pltserver(iPilot), _
                              iPilot, _
                              dtPilots)
                End If
                If pltserver(iPilot).Status = 2 Then
                    pltserver(iPilot).tmFlight += 1
                End If
                If pltserver(iPilot).Status > 2 Then
                    pltserver(iPilot).tmGround += 1
                    If pltserver(iPilot).tmGround > config_info.tmAllowGnd Then
                        KickPlt(pltserver(iPilot).CallSign, _
                                config_info)
                        SendAllMess(pltserver(iPilot).CallSign & " kicked because inactive!", _
                                    config_info)
                        pltserver(iPilot).tmGround = 0
                    End If
                End If
            Next

            Select Case mission_info.iTimeLeft
                Case Is < 1
                    frmMain.cmdExit.Enabled = False
                    SendAllMess("Mission is ending!", _
                                config_info)

                    EndMission(config_info, _
                            mission_info, _
                            pltSide)
                    mission_info.bMissEnd = True
                Case Is = 1
                    SendAllMess("1 minute until mission ends!", _
                                config_info)
                Case Is = 5
                    SendAllMess("5 minutes until mission ends!", _
                                config_info)
                Case Is = 10
                    SendAllMess("10 minutes until mission ends!", _
                                config_info)
                Case Is = 15
                    SendAllMess("15 minutes until mission ends!", _
                                config_info)
            End Select
            mission_info.iDelayLeft -= 1
            If mission_info.iDelayLeft = 0 Then SendAllMess("Clear to take off!", _
                                                            config_info)
            If mission_info.iDelayLeft > 0 Then SendAllMess(Str(mission_info.iDelayLeft) & " minutes until take off!", _
                                                            config_info)
            If LogDestroy.Length > 1 Then
                For iCount = 1 To LogDestroy.Length - 1
                    SendArmyMess(LogDestroy(iCount).Text, _
                                 LogDestroy(iCount).Side, _
                                 config_info)
                Next
                ReDim LogDestroy(0)
            End If
        End If
        MoveCarriers(carrier, _
                        carrierwp, _
                        airbase)
        lFileSize = My.Computer.FileSystem.GetFileInfo(config_info.sEventLog).Length
        If lFileSize >= mission_info.lLogSize Then
            mission_info.lLogSize = lFileSize
            FileOpen(1, _
                     config_info.sEventLog, _
                     OpenMode.Input, _
                     OpenAccess.Read, _
                     OpenShare.Shared)
            For lLine = 1 To mission_info.lLogLine
                sinput = LineInput(1)
            Next lLine
            Do Until EOF(1)
                mission_info.lLogLine += 1
                sinput = LineInput(1)
                If InStr(sinput, "is Playing") < 1 And _
                            InStr(sinput, "[") > 0 And _
                            InStr(sinput, "]") > 0 And _
                            frmMain.cbDebug.CheckState <> 1 Then
                    iStart = InStr(sinput, "]") + 1
                    sinput = Mid(sinput, iStart)
                    sdate = CDate("00:00:00")
                    sdate = DateAdd(DateInterval.Second, Int(3600 * dbTime), sdate)
                    sinput = "[" & Format(sdate, "h:mm:ss tt") & "]" & sinput
                End If

                If sPrevious <> sinput Then
                    ReDim sLog_Temp(0)
                    ReDim Preserve sloginput(sloginput.Length)
                    sloginput(sloginput.Length - 1) = sinput
                    sPrevious = sinput
                    If InStr(sinput, "Mission BEGIN") > 0 Then FindMinute(sinput, _
                                                                        mission_info.iMissStart)
                    'Connection Events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, "has connected") > 0 Then HasConn(sinput, _
                                                                        pltserver, _
                                                                        config_info, _
                                                                        mission_info, _
                                                                        pltSide, _
                                                                        dtPilots)
                    If InStr(sinput, "has disconnected") > 0 Then HasDisconn(sinput, _
                                                                        pltserver, _
                                                                        Squad, _
                                                                        Infantry, _
                                                                        mission_info, _
                                                                        sLog_Temp, _
                                                                        dtPilots, _
                                                                        dtSquadrons, _
                                                                        config_info)
                    'Fly/Refly Events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, " seat occupied by ") > 0 Then Seat_Occupied_By(sinput, _
                                                                    pltserver, _
                                                                    airbase, _
                                                                    config_info)
                    If InStr(sinput, "loaded weapons") > 0 Then Loaded_Weapons(sinput, _
                                                                        pltserver, _
                                                                        Squad, _
                                                                        mission_info, _
                                                                        SupplyAC, _
                                                                        Infantry, _
                                                                        pltSide, _
                                                                        dtPilots, _
                                                                        dtSquadrons, _
                                                                        config_info)
                    If InStr(sinput, "entered refly menu") > 0 Then Refly(sinput, _
                                                                        pltserver, _
                                                                        Squad, _
                                                                        sLog_Temp, _
                                                                        Infantry, _
                                                                        dtPilots, _
                                                                        dtSquadrons, _
                                                                        config_info)
                    'Takeoff Landing Events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, "in flight") > 0 Then InFlight(sinput, _
                                                                    pltserver, _
                                                                    Squad, _
                                                                    mission_info, _
                                                                    sLog_Temp, _
                                                                    dtPilots, _
                                                                    dtSquadrons, _
                                                                    config_info)
                    If InStr(sinput, "landed at") > 0 Then Landed_at(sinput, _
                                                                pltserver, _
                                                                Squad, _
                                                                mission_info, _
                                                                config_info, _
                                                                airbase, _
                                                                Infantry, _
                                                                sLog_Temp, _
                                                                dtPilots)
                    'Bail events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, "(0) bailed out at ") > 0 Then Bailed(sinput, _
                                                                        pltserver, _
                                                                        Squad, _
                                                                        Infantry, _
                                                                        config_info, _
                                                                        sLog_Temp, _
                                                                        dtPilots, _
                                                                        dtSquadrons)

                    If InStr(sinput, "(0) was killed in his chute by ") > 0 Then
                        'Remove Chute Kills if killed by enemy pilot
                        logPilotAC(sinput, _
                                   iPilot, _
                                   pltserver)
                        If iPilot > 0 Then
                            logPilotBy(sinput, _
                                       iPilot2, _
                                       pltserver)
                            If iPilot2 > 0 Then
                                'if pilot was not killed by himself and was not killed in the chute by enemy pilot
                                If iPilot2 <> iPilot And _
                                    pltserver(iPilot).Side <> pltserver(iPilot2).Side Then
                                    'delete string
                                    sinput = ""
                                Else
                                    'kill the pilot
                                    iStart = sinput.IndexOf("at")
                                    wasKilledIndex = sinput.IndexOf("was killed")
                                    If (sinput.Contains("in his chute")) Then
                                        sinput = sinput.Remove(wasKilledIndex + 11, iStart - wasKilledIndex - 11)
                                    End If
                                End If
                            End If

                        End If
                    End If
                    'Pilot Events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, "(0) was captured") > 0 Then Captured(sinput, _
                                                                        pltserver, _
                                                                        Squad, _
                                                                        Infantry, _
                                                                        config_info, _
                                                                        dtPilots, _
                                                                        dtSquadrons)
                    If InStr(sinput, "(0) was killed at") > 0 Then Killed_At(sinput, _
                                                                    pltserver, _
                                                                    Squad, _
                                                                    Infantry, _
                                                                    config_info, _
                                                                    sLog_Temp, _
                                                                    dtPilots)
                    If InStr(sinput, "(0) was killed by") > 0 Then Killed_By(sinput, _
                                                                    pltserver, _
                                                                    Squad, _
                                                                    Infantry, _
                                                                    config_info, _
                                                                    sLog_Temp, _
                                                                    dtPilots)
                    'Aircraft Events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, "shot down") > 0 Then ShotDown(sinput, _
                                                                pltserver, _
                                                                Squad, _
                                                                Infantry, _
                                                                config_info, _
                                                                mission_info, _
                                                                sLog_Temp, _
                                                                dtPilots, _
                                                                dtSquadrons)

                    If InStr(sinput, "destroyed by") > 0 And _
                    InStr(sinput, " has chute destroyed by ") < 1 Then Destroyed_By(sinput, _
                                                                             LogDestroy, _
                                                                             Squad, _
                                                                             mission_info, _
                                                                             MissLine, _
                                                                             airbase, _
                                                                             pltserver, _
                                                                             config_info, _
                                                                             dtSquadrons, _
                                                                             Transport, _
                                                                             sLog_Temp)
                    If sinput.Contains("ExplosiveDamage") And _
                        sinput.Contains("_plate") Then Plate_Damaged(sinput, _
                                                                             LogDestroy, _
                                                                             Squad, _
                                                                             mission_info, _
                                                                             MissLine, _
                                                                             airbase, _
                                                                             pltserver, _
                                                                             config_info, _
                                                                             dtSquadrons, _
                                                                             sLog_Temp)
                    If InStr(sinput, " crashed at") > 0 Then Crashed(sinput, _
                                                                    pltserver, _
                                                                    Squad, _
                                                                    Infantry, _
                                                                    config_info, _
                                                                    mission_info, _
                                                                    dtPilots, _
                                                                    dtSquadrons)
                    If InStr(sinput, " damaged by ") > 0 Then Damaged_By(sinput, _
                                                                    pltserver)
                    If InStr(sinput, " damaged on the ground at ") > 0 Then Damaged_On_Ground(sinput, _
                                                                    pltserver, _
                                                                    Squad, _
                                                                    Infantry, _
                                                                    config_info, _
                                                                    mission_info, _
                                                                    dtPilots)
                    'Other Events!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    If InStr(sinput, " turned ") > 0 Then Toggle_Smoke(sinput, _
                                                                pltserver, _
                                                                config_info, _
                                                                mission_info, _
                                                                flRed, _
                                                                flBlue, _
                                                                sLog_Temp, _
                                                                Infantry, _
                                                                dtPilots)

                    If sinput <> sloginput(sloginput.Length - 1) Then sloginput(sloginput.Length - 1) = sinput
                    If sloginput(sloginput.Length - 1) = "" Then ReDim Preserve sloginput(sloginput.Length - 2)
                    If sLog_Temp.Length > 1 Then
                        For iCount = 1 To sLog_Temp.Length - 1
                            ReDim Preserve sloginput(sloginput.Length)
                            sloginput(sloginput.Length - 1) = sLog_Temp(iCount)
                        Next
                    End If
                End If
            Loop
            FileClose(1)
        End If
        If mission_info.bMissEnd Or frmMain.cbDebug.CheckState > 0 Then
            ReDim Preserve sloginput(sloginput.Length)
            sdate = CDate("00:00:00")
            sdate = DateAdd(DateInterval.Second, Int(3600 * dbTime), sdate)
            sloginput(sloginput.Length - 1) = "[" & Format(sdate, "h:mm:ss tt") & "]" & " Mission END"
        End If
        frmMain.tbSide.Text = Str(mission_info.iSeats)
        frmMain.tbRedPilots.Text = Str(mission_info.iRedSide)
        frmMain.tbBluePilots.Text = Str(mission_info.iBlueSide)
    End Sub


    Public Sub FindCapt(ByRef sline As String, _
                        ByRef pltserver As Pilot_Class, _
                        ByRef bCapt As Boolean, _
                        ByRef FLM() As Marker_Class)
        Dim dX As Double
        Dim dY As Double
        Dim dDistRed As Double
        Dim dDistBlue As Double
        Dim dDist As Double
        Dim i As Short
        FindLoc(sline, dX, dY)
        If FLM.Length > 1 Then
            For i = 1 To FLM.Length - 1
                dDist = System.Math.Sqrt(((dX - FLM(i).X) ^ 2) + ((dY - FLM(i).Y) ^ 2))
                If FLM(i).Side = 1 Then
                    If dDistRed = 0 Then
                        dDistRed = dDist
                    Else
                        If dDist < dDistRed Then dDistRed = dDist
                    End If
                End If
                If FLM(i).Side = 2 Then
                    If dDistBlue = 0 Then
                        dDistBlue = dDist
                    Else
                        If dDist < dDistBlue Then dDistBlue = dDist
                    End If
                End If
            Next
            If pltserver.Side = 1 Then
                If dDistRed < dDistBlue Then
                    bCapt = False
                Else
                    dDist = Rnd()
                    If dDist < 0.2 Then bCapt = False
                End If
            End If
            If pltserver.Side = 2 Then
                If dDistRed > dDistBlue Then
                    bCapt = False
                Else
                    dDist = Rnd()
                    If dDist < 0.2 Then bCapt = False
                End If
            End If
        End If
    End Sub

    Public Sub LoadSupply(ByRef mission_info As Mission_Class, _
                          ByRef supplyac() As String)
        Dim sinput As String = ""
        mission_info.RedSupplyBase = "redbase"
        mission_info.BlueSupplyBase = "bluebase"
        FileOpen(10, _
                    mission_info.sPropFile, _
                    OpenMode.Input, _
                    OpenAccess.Read, _
                    OpenShare.Shared)
        Do Until EOF(10)
            sinput = LineInput(10)
            If sinput.Contains("<ARMY SUPPLY>") And _
                    sinput.Contains("</ARMY SUPPLY>\n") Then
                sinput = sinput.Replace("<ARMY SUPPLY>", "")
                sinput = sinput.Replace("</ARMY SUPPLY>\n", "")
                Dim strArray() As String
                strArray = sinput.Split(":")
                For i = 0 To strArray.Length - 1
                    Select Case i
                        Case 0 'Red Base
                            mission_info.RedSupplyBase = strArray(i)
                        Case 1 'Blue Base
                            mission_info.BlueSupplyBase = strArray(i)
                        Case 2 'Loadout
                            mission_info.sSupplyLoad = strArray(i)
                        Case Else 'Aircraft
                            If strArray(i) <> "" Then
                                ReDim Preserve supplyac(supplyac.Length)
                                supplyac(supplyac.Length - 1) = strArray(i)
                            End If
                    End Select
                Next
                If supplyac.Length < 2 Then
                    ReDim Preserve supplyac(supplyac.Length)
                    supplyac(supplyac.Length - 1) = "redac"
                End If
            End If
        Loop
        FileClose(10)
    End Sub
    Public Sub Sides(ByRef strLog As String, _
                     ByRef mission_info As Mission_Class, _
                     ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim sMessage As String
        iStart = InStr(strLog, "Chat: ") + 6
        iLen = InStr(strLog, ": \t") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        sMessage = Format(mission_info.iRedSide, "0") & " Red " & Format(mission_info.iBlueSide, "0") & " Blue"
        SendPvtMess(sPilot, _
                    sMessage, _
                    config_info)
    End Sub
    Public Sub Load_Transports(ByRef mission_info As Mission_Class, _
                               ByRef transport() As Carry)
        Dim sinput As String = ""
        FileOpen(6, _
                mission_info.sPropFile, _
                OpenMode.Input, _
                OpenAccess.Read, _
                OpenShare.Shared)
        Do Until EOF(6)
            sinput = LineInput(6)
            If sinput.Contains("<ARMY TRANSPORT>") And _
                    sinput.Contains("</ARMY TRANSPORT>\n") Then
                sinput = sinput.Replace("<ARMY TRANSPORT>", "")
                sinput = sinput.Replace("</ARMY TRANSPORT>\n", "")
                Dim strArray() As String
                strArray = sinput.Split(":")
                If strArray.Length > 1 Then
                    ReDim Preserve transport(transport.Length)
                    transport(transport.Length - 1).Main = strArray(0)
                    transport(transport.Length - 1).Secondary = strArray(1)
                End If
            End If

        Loop
        FileClose(6)
    End Sub
    Public Sub LoadWeapons(ByRef mission_info As Mission_Class, _
                           ByRef Squad() As Squad_Class)
        Dim sAircraft As String
        'Load weapons restrictions from weapons.dcg
        Dim sInput As String = ""
        Dim sWeap As String
        Dim i As Short
        If My.Computer.FileSystem.FileExists(mission_info.sPropFile) Then
            FileOpen(11, _
                     mission_info.sPropFile, _
                     OpenMode.Input, _
                     OpenAccess.Read, _
                     OpenShare.Shared)
            Do Until EOF(11)
                sInput = LineInput(11)
                If sInput.Contains("<ARMY WEAPONS>") And _
                        sInput.Contains("</ARMY WEAPONS>\n") Then
                    sInput = sInput.Replace("<ARMY WEAPONS>", "")
                    sInput = sInput.Replace("</ARMY WEAPONS>\n", "")
                    Dim strArray() As String
                    strArray = sInput.Split(":")
                    If strArray.Length > 1 Then
                        sAircraft = strArray(0)
                        sWeap = strArray(1)
                        For i = 1 To Squad.Length - 1
                            If sAircraft = Squad(i).Coop Or sAircraft = Squad(i).DF Then
                                Squad(i).Weapon = sWeap
                            End If
                        Next
                    End If
                End If
            Loop

            FileClose(11)
        End If

    End Sub
    Public Sub FindIP(ByVal sData As String, _
                        ByRef pltside() As PilotData_Class)
        Dim sPilot As String
        Dim iPilot As Short
        Dim sIP As String
        Dim iStart As Short
        Dim iEnd As Short
        If pltside.Length < 2 Then Exit Sub
        'find Pilot Name
        iStart = InStr(sData, "ip ")
        iEnd = InStr(iStart, sData, ":")
        sIP = Trim(Mid(sData, iStart + 3, iEnd - iStart - 3))
        iStart = InStr(iEnd, sData, ", ")
        iEnd = InStr(iStart, sData, ", is complete")
        sPilot = Trim(Mid(sData, iStart + 2, iEnd - iStart - 2))
        For iPilot = pltside.Length - 1 To 1 Step -1
            With pltside(iPilot)
                If LCase(sPilot) = LCase(.CallSign) Then
                    .IP = sIP
                    Exit For
                End If
            End With
        Next
        If iPilot < 1 Then
            ReDim Preserve pltside(pltside.Length)
            With pltside(pltside.Length - 1)
                .CallSign = sPilot
                .Side = 0
                .IP = sIP
            End With
        End If
    End Sub
    Public Sub LoadCarriers(ByRef airbase() As Airbase_Class, _
                            ByRef missline() As String, _
                            ByRef carrier() As CarrierType, _
                            ByRef carrierwp() As CarrierWPType)
        Dim iBP As Short
        Dim iWp As Short
        Dim bolFound As Boolean
        Dim sline As String
        Dim sX As String
        Dim sY As String
        Dim dX As Double
        Dim dY As Double
        Dim dDistance As Double
        Dim ipos As Short
        For iBP = 1 To airbase.Length - 1
            If InStr(airbase(iBP).Location, "_Chief") > 0 Then
                For iWp = 1 To missline.Length - 1
                    If InStr(missline(iWp), "[") > 0 And bolFound Then
                        With carrier(carrier.Length - 1)
                            .LastX = carrierwp(.StartWP).X
                            .LastY = carrierwp(.StartWP).Y
                            .Speed = carrierwp(.StartWP).Speed
                            dX = carrierwp(.StartWP + 1).X - carrierwp(.StartWP).X
                            dY = carrierwp(.StartWP + 1).Y - carrierwp(.StartWP).Y
                            dDistance = Int(System.Math.Sqrt((dX ^ 2) + (dY ^ 2)))
                            .RunTime = Int(dDistance / .Speed)
                            .XSpeed = dX / .RunTime
                            .YSpeed = dY / .RunTime
                        End With
                        bolFound = False
                    End If
                    If Trim(missline(iWp)) <> "" And bolFound Then
                        ReDim Preserve carrierwp(carrierwp.Length)
                        carrier(carrier.Length - 1).EndWP = carrierwp.Length - 1
                        With carrierwp(carrierwp.Length - 1)
                            sline = Trim(missline(iWp))
                            ipos = InStr(sline, " ")
                            sX = Trim(Left(sline, ipos))
                            .X = Val(sX)
                            sline = Trim(Mid(sline, ipos))
                            ipos = InStr(sline, " ")
                            sY = Trim(Left(sline, ipos))
                            .Y = Val(sY)
                            sline = Trim(Mid(sline, ipos))
                            ipos = InStr(sline, " ")
                            If ipos > 0 Then
                                sline = Trim(Mid(sline, ipos))
                                If InStr(sline, ".") > 0 Then
                                    ipos = InStr(sline, " ")
                                    sline = Trim(Mid(sline, ipos))
                                    ipos = InStr(sline, " ")
                                    sline = Trim(Mid(sline, ipos))
                                    .Speed = Val(sline)
                                End If
                            End If
                        End With
                    End If
                    If InStr(missline(iWp), "[" & airbase(iBP).Location & "0_Road]") > 0 Then
                        ReDim Preserve carrier(carrier.Length)
                        With carrier(carrier.Length - 1)
                            .Airbase = iBP
                            .CurrentWP = carrierwp.Length
                            .EndWP = carrierwp.Length
                            .StartWP = carrierwp.Length
                        End With
                        bolFound = True
                    End If
                Next
            End If
        Next
    End Sub
    Public Sub MoveCarriers(ByRef carrier() As CarrierType, _
                            ByRef carrierwp() As CarrierWPType, _
                            ByRef airbase() As Airbase_Class)
        Dim iCar As Short
        Dim dDistance As Double
        Dim dX As Double
        Dim dY As Double
        If carrier.Length < 2 Then Exit Sub
        For iCar = 1 To carrier.Length - 1
            With carrier(iCar)
                .RunTime = .RunTime - 15
                If .RunTime <= 0 Then
                    .CurrentWP = .CurrentWP + 1
                    If .CurrentWP >= .EndWP Then
                        .CurrentWP = .EndWP
                        .LastX = carrierwp(.CurrentWP).X
                        .LastY = carrierwp(.CurrentWP).Y
                        .XSpeed = 0
                        .YSpeed = 0
                        .RunTime = 3600
                    Else
                        .LastX = carrierwp(.CurrentWP).X
                        .LastY = carrierwp(.CurrentWP).Y
                        .Speed = carrierwp(.CurrentWP).Speed
                        dX = carrierwp(.CurrentWP + 1).X - carrierwp(.CurrentWP).X
                        dY = carrierwp(.CurrentWP + 1).Y - carrierwp(.CurrentWP).Y
                        dDistance = Int(System.Math.Sqrt((dX ^ 2) + (dY ^ 2)))
                        .RunTime = Int(dDistance / .Speed)
                        .XSpeed = dX / .RunTime
                        .YSpeed = dY / .RunTime
                        'If airbase(.Airbase).Location = "601_Chief" Then SendAllMess(airbase(.Airbase).Location & " next WP" _
                        '                & " " & Format(.LastX, "0") _
                        '               & " " & Format(.LastY, "0"))
                    End If
                Else
                    .LastX = .LastX + (.XSpeed * 15)
                    .LastY = .LastY + (.YSpeed * 15)
                    'If airbase(.Airbase).Location = "601_Chief" Then SendAllMess(airbase(.Airbase).Location & " " & Format(.LastX, "0") _
                    '                & " " & Format(.LastY, "0"))
                End If
                airbase(.Airbase).X = .LastX
                airbase(.Airbase).Y = .LastY
            End With

        Next
    End Sub
    Public Sub Load_Infantry(ByRef mission_Info As Mission_Class, _
                             ByRef infantry() As Infant_Class, _
                             ByRef config_info As Config_Class)
        Dim sinput As String = ""
        FileOpen(5, _
                mission_Info.sPropFile, _
                OpenMode.Input, _
                OpenAccess.Read, _
                OpenShare.Shared)
        Do Until EOF(5)
            sinput = LineInput(5)
            If sinput.Contains("<INFANTRY>") And _
                    sinput.Contains("</INFANTRY>\n") Then
                sinput = sinput.Replace("<INFANTRY>", "")
                sinput = sinput.Replace("</INFANTRY>\n", "")
                Dim strarray() As String
                strarray = sinput.Split(":")
                If strarray.Length > 1 Then
                    ReDim Preserve infantry(infantry.Length)
                    With infantry(infantry.Length - 1)
                        .Location = strarray(0)
                        .Ident = strarray(1)
                    End With
                End If
            End If

        Loop
        FileClose(5)

    End Sub
    Public Sub Infantry_Drop(ByRef strLog As String, _
                            ByRef infantry() As Infant_Class, _
                            ByRef pltserver() As Pilot_Class, _
                            ByRef squad() As Squad_Class, _
                            ByRef dtPilots As DataTable, _
                            ByRef dtSquadrons As DataTable, _
                            ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        iStart = InStr(strLog, "] ") + 2
        iLen = InStr(strLog, "(255)") - iStart
        sPilot = Mid(strLog, iStart, iLen)
        iStart = InStr(sPilot, ":")
        If iStart < 1 Then Exit Sub
        sPilot = Left(sPilot, iStart - 1)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            If .InfantryMission > 0 Then
                strLog = Replace(strLog, "(255) successfully bailed out at ", " moved " & infantry(.InfantryMission).Ident & " at ")
                'UPGRADE_WARNING: Couldn't resolve default property of object moved. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                infantry(.InfantryMission).Location = "dropped"
                infantry(.InfantryMission).Status = 0
                .InfantryMission = 0
                .Allow_Drop = 0
                SendPvtMess(sPilot, _
                            " infantry dropped!", _
                            config_info)
            End If
            If .Squad > 0 And .Status < 2 Then
                squad(.Squad).Number = squad(.Squad).Number + 1
                UpDateSquadsLine(squad, _
                                 .Squad, _
                                 dtSquadrons)
            End If

        End With

        UpDatePlt(pltserver(iPilot), _
                  iPilot, _
                  dtPilots)
    End Sub
    Public Sub Load_Troops_on_AC(ByVal sLog As String, _
                                 ByRef pltserver() As Pilot_Class, _
                                 ByVal SupplyAC() As String, _
                                 ByRef Infantry() As Infant_Class, _
                                 ByRef config_info As Config_Class)
        Dim iStart As Short
        Dim iLen As Short
        Dim sPilot As String
        Dim iPilot As Short
        Dim i As Short
        iStart = InStr(sLog, "Chat: ") + 6
        iLen = InStr(sLog, ": \t") - iStart
        sPilot = Mid(sLog, iStart, iLen)
        FindPilot(sPilot, _
                  iPilot, _
                  pltserver)
        If iPilot < 1 Then
            SendPvtMess(sPilot, _
                        "Cannot find you in pilot list!", _
                        config_info)
            KickPlt(sPilot, _
                    config_info)
            Exit Sub
        End If
        With pltserver(iPilot)
            If .Squad > 0 And _
                    .Status = 1 And _
                    SupplyAC.Length > 1 And _
                    Infantry.Length > 1 And _
                    .InfantryMission < 1 Then
                For i = SupplyAC.Length - 1 To 1 Step -1
                    If .Aircraft = SupplyAC(i) Then Exit For
                Next
                If i > 0 Then
                    For i = Infantry.Length - 1 To 1 Step -1
                        If Infantry(i).Location = .Base And _
                                Infantry(i).Status = 0 Then
                            Exit For
                        End If
                    Next
                    If i > 0 Then
                        .SupplyMission = 0
                        .Allow_Drop = 0
                        .InfantryMission = i
                        Infantry(i).Status = 1
                        SendPvtMess(sPilot, _
                                    "Infantry loaded from " & .Base & "!", _
                                    config_info)
                    Else
                        SendPvtMess(sPilot, _
                                    "No infantry at " & .Base & "!", _
                                    config_info)
                    End If
                Else
                    SendPvtMess(sPilot, _
                                "Cannot load infantry!", _
                                config_info)
                End If
            Else
                SendPvtMess(sPilot, _
                            "Cannot load infantry!", _
                            config_info)
            End If
        End With
    End Sub
    Public Sub PilotDataTable(ByRef dtPilots As DataTable)
        With dtPilots.Columns
            .Add("CallSign")
            .Add("Squad")
            .Add("Aircraft")
            .Add("Base")
            .Add("Side")
            .Add("Kick")
            .Add("Kicks")
            .Add("LocX")
            .Add("LocY")
            .Add("HomeX")
            .Add("HomeY")
        End With
    End Sub
    Public Sub SquadDataTable(ByRef dtSquadrons As DataTable)
        With dtSquadrons.Columns
            .Add("Coop")
            .Add("DF")
            .Add("Base")
            .Add("Side")
            .Add("Available")
            .Add("Weapons")
            .Add("Suppressed")
            .Add("Fuel_Limit")
            .Add("X")
            .Add("Y")
        End With
    End Sub
    Public Sub BaseDataTable(ByRef dtBases As DataTable)
        With dtBases.Columns
            .Add("Location")
            .Add("Side")
            .Add("X")
            .Add("Y")
            .Add("Radius")
            .Add("Suppressed")
            .Add("Supplies")
            .Add("Fuel")
            .Add("Fuel_Limit")
        End With
    End Sub
    Public Sub Fill_Form(ByRef config_info As Config_Class)
        With config_info
            frmMain.tbEventlog.Text = .sEventLog
            frmMain.tbIP.Text = .sIP
            frmMain.tbPort.Text = Format(.iPort, "0")
            frmMain.tbTimeLeft.Text = Format(.iMissionLength + .iDelay, "0")
            frmMain.tbWelcome.Text = .sWelcome
            frmMain.nBail.Value = .iBail
            frmMain.nCapture.Value = .iCapture
            frmMain.nDeath.Value = .iDeath
            frmMain.nDelay.Value = .iDelay
            frmMain.nKicks.Value = .iKicksAllowed
            frmMain.nMission.Value = .iMissionLength
            frmMain.nradarRange.Value = .iRadarRange
            frmMain.nRearm.Value = .iRearm
            frmMain.nValidFlight.Value = .iValidFlight
            frmMain.nErrorTimeout.Value = .iErrorTimeout
            If .iBlockPlt > 0 Then
                frmMain.cbBlock.Checked = True
            Else
                frmMain.cbBlock.Checked = False
            End If
            If .iWritePltFile > 0 Then
                frmMain.cbWritePlt.Checked = True
            Else
                frmMain.cbWritePlt.Checked = False
            End If
            If .iBridge > 0 Then
                frmMain.cbBridge.Checked = True
            Else
                frmMain.cbBridge.Checked = False
            End If
            If .iSupBase > 0 Then
                frmMain.rbAllBases.Checked = False
                frmMain.rbSupplyBases.Checked = True
            Else
                frmMain.rbAllBases.Checked = True
                frmMain.rbSupplyBases.Checked = False
            End If
        End With
    End Sub
    Public Sub TCPConnect(ByRef config_info As Config_Class)
        Try
            config_info.client = New TcpClient(config_info.sIP, config_info.iPort)
            config_info.stream = config_info.client.GetStream
            frmMain.tmrTCP_Read.Enabled = True
        Catch
            If MsgBox("Problems connecting to server!", MsgBoxStyle.AbortRetryIgnore) = MsgBoxResult.Retry Then
                TCPConnect(config_info)
            End If
        End Try
    End Sub
    Public Sub TCPClose(ByRef config_info As Config_Class)
        config_info.client.Close()
        config_info.stream.Close()
    End Sub
    Public Sub TCPSend(ByRef config_info As Config_Class, _
                       ByVal sMessage As String)
        Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(sMessage)
        config_info.stream.Write(data, 0, data.Length)
    End Sub
    Public Sub TCPReceive(ByRef config_info As Config_Class, _
                          ByRef sResponse As String)
        Dim data As [Byte]()
        data = New [Byte](1024) {}
        sResponse = String.Empty
        If config_info.stream.DataAvailable Then
            Dim bytes As Int32 = config_info.stream.Read(data, 0, data.Length)
            sResponse = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
        End If
    End Sub
    Public Sub UpDateBases(ByRef AirBases() As Airbase_Class, _
                                ByRef iBase As Short, _
                                ByRef dtAirBases As DataTable)
        Dim rows() As DataRow
        Dim sSearch As String
        sSearch = "Location='" & AirBases(iBase).Location & "'"
        rows = dtAirBases.Select(sSearch)
        If rows.Length > 0 Then
            rows(0)("Location") = AirBases(iBase).Location
            rows(0)("Side") = AirBases(iBase).Side
            rows(0)("X") = AirBases(iBase).X
            rows(0)("Y") = AirBases(iBase).Y
            rows(0)("Radius") = AirBases(iBase).Radius
            rows(0)("Suppressed") = AirBases(iBase).Suppressed
            rows(0)("Supplies") = AirBases(iBase).Supplies
            rows(0)("Fuel") = AirBases(iBase).Fuel
            rows(0)("Fuel_Limit") = AirBases(iBase).FuelLimit
        Else
            Dim newrow As DataRow = dtAirBases.NewRow
            newrow("Location") = AirBases(iBase).Location
            newrow("Side") = AirBases(iBase).Side
            newrow("X") = AirBases(iBase).X
            newrow("Y") = AirBases(iBase).Y
            newrow("Radius") = AirBases(iBase).Radius
            newrow("Suppressed") = AirBases(iBase).Suppressed
            newrow("Supplies") = AirBases(iBase).Supplies
            newrow("Fuel") = AirBases(iBase).Fuel
            newrow("Fuel_Limit") = AirBases(iBase).FuelLimit
            dtAirBases.Rows.Add(newrow)
        End If

    End Sub
    Public Sub Plate_Damaged(ByRef strLog As String, _
                            ByRef logdestroy() As DestObj, _
                            ByRef squad() As Squad_Class, _
                            ByRef mission_info As Mission_Class, _
                            ByRef missline() As String, _
                            ByRef airbase() As Airbase_Class, _
                            ByRef pltServer() As Pilot_Class, _
                            ByRef config_info As Config_Class, _
                            ByRef dtSquadrons As DataTable, _
                            ByRef sLog_Temp() As String)
        Dim i As Short
        Dim strObject As String = ""
        Dim strSearch As String = ""
        Dim dbX As Double
        Dim dbY As Double
        Dim intX As Integer
        Dim intY As Integer
        Dim sX As String = ""
        Dim sY As String = ""
        Dim iside As Short
        Dim strMess As String
        Dim sBase As String = ""
        Dim sType As String = ""
        Dim sPilot As String = ""
        Dim iPilot As Integer

        Dim sArray() As String
        sArray = strLog.Split(" ")
        For i = 0 To sArray.Length - 1
            If i = 3 Then strObject = sArray(i)
            If i = 10 Then sPilot = Left(sArray(i), sArray(i).Length - 2)
            If i = 13 Then dbX = Val(sArray(i))
            If i = 14 Then dbY = Val(sArray(i))
        Next
        SearchMiss(strObject, _
                       sType, _
                       iside, _
                       missline)
        FindPilot(sPilot, _
                    iPilot, _
                    pltServer)
        If dbX <> 0 And dbY <> 0 And iPilot > 0 Then
            intX = Int((dbX - mission_info.XOffset) / 10000) + 1
            intY = Int((dbY - mission_info.YOffset) / 10000)
            sY = Str(intY + 1)
            sX = ""
            sX = Chr(65 + intX \ 26)
            sX = sX & Chr(64 + intX Mod 26)
            strMess = "INTEL: Factory Damaged at: " & sX & sY
            If iside > 0 Then
                ReDim Preserve logdestroy(logdestroy.Length)
                logdestroy(logdestroy.Length - 1).Text = strMess
                logdestroy(logdestroy.Length - 1).Side = iside
            End If
            If pltServer(iPilot).Side <> iside Then
                pltServer(iPilot).iSuccess = 1
                strMess = ("Enemy Factory Damaged")
            Else
                strMess = ("Friendly Factory Damaged")
            End If
            SendPvtMess(sPilot, strMess, config_info)
        End If
    End Sub
End Module